Click here to Skip to main content
15,887,083 members
Home / Discussions / C#
   

C#

 
GeneralRe: TaskFactory Class Pin
Member 1371053019-Mar-18 18:00
Member 1371053019-Mar-18 18:00 
Questionc# parsing CAN dbc files Pin
Member 135713645-Mar-18 4:05
Member 135713645-Mar-18 4:05 
AnswerRe: c# parsing CAN dbc files Pin
Maciej Los5-Mar-18 20:27
mveMaciej Los5-Mar-18 20:27 
GeneralRe: c# parsing CAN dbc files Pin
Member 135713645-Mar-18 20:34
Member 135713645-Mar-18 20:34 
Questiontextbox input Pin
User 136751143-Mar-18 13:01
User 136751143-Mar-18 13:01 
AnswerRe: textbox input Pin
BillWoodruff3-Mar-18 14:31
professionalBillWoodruff3-Mar-18 14:31 
GeneralRe: textbox input Pin
User 136751143-Mar-18 23:56
User 136751143-Mar-18 23:56 
GeneralRe: textbox input PinPopular
OriginalGriff4-Mar-18 1:21
mveOriginalGriff4-Mar-18 1:21 
And there is your problem:
Form 1 does this:
private void button1_Click(object sender, EventArgs e)
{
    Form2 form2sec = new Form2();
    form2sec.Show();
    Hide();
}
And Form2 does this:
private void button5_Click(object sender, EventArgs e)
{
    Form1 form1sec = new Form1();
    form1sec.Show();
    Hide();
}
Which means that each time you click a button, you create a new instance of the form. That's not the same as previous one!
Think of it like this:
You get into your car, and put your phone in the glove box. Then you buy a new car. Would you expect your phone to be in the new car's glove box? Of course not! You know the difference between "this car" and "that car", "old car" and "new car" - and you know that whatever is in the glove box of one car is not in the glove box of any other.

Computer classes work the same way: Each time you use the new keyword you are "buying a new car" - only it's a form instead of a car!
What you need to do probably most easily done like this:
Form1:
private void button1_Click(object sender, EventArgs e)
        {
            Form2 form2sec = new Form2();
            form2sec.ShowDialog();
            string valueFromForm2 = form2sec.getTheValueProperty;
        }
Form2:
        private void button5_Click(object sender, EventArgs e)
        {
            Close();
        }
public string getTheValueProperty
        {
        get { return myTextBox.Text; }
        }

Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

GeneralRe: textbox input Pin
BillWoodruff4-Mar-18 2:18
professionalBillWoodruff4-Mar-18 2:18 
GeneralRe: textbox input Pin
Luc Pattyn4-Mar-18 7:19
sitebuilderLuc Pattyn4-Mar-18 7:19 
GeneralRe: textbox input Pin
OriginalGriff4-Mar-18 19:27
mveOriginalGriff4-Mar-18 19:27 
GeneralRe: textbox input Pin
Pete O'Hanlon4-Mar-18 20:56
mvePete O'Hanlon4-Mar-18 20:56 
GeneralRe: textbox input Pin
OriginalGriff4-Mar-18 21:04
mveOriginalGriff4-Mar-18 21:04 
GeneralRe: textbox input Pin
Pete O'Hanlon4-Mar-18 21:10
mvePete O'Hanlon4-Mar-18 21:10 
QuestionHow to create a recursive lambda function ? Pin
Jesus Carroll2-Mar-18 12:26
professionalJesus Carroll2-Mar-18 12:26 
AnswerRe: How to create a recursive lambda function ? PinPopular
Eddy Vluggen2-Mar-18 12:32
professionalEddy Vluggen2-Mar-18 12:32 
PraiseRe: How to create a recursive lambda function ? Pin
Jesus Carroll2-Mar-18 12:48
professionalJesus Carroll2-Mar-18 12:48 
GeneralRe: How to create a recursive lambda function ? Pin
Eddy Vluggen2-Mar-18 13:05
professionalEddy Vluggen2-Mar-18 13:05 
AnswerRe: How to create a recursive lambda function ? Pin
jschell3-Mar-18 11:00
jschell3-Mar-18 11:00 
AnswerRe: How to create a recursive lambda function ? Pin
Richard Deeming5-Mar-18 8:08
mveRichard Deeming5-Mar-18 8:08 
QuestionMove Up And Down rows in datagridview and update it in database Pin
Member 133258462-Mar-18 10:49
Member 133258462-Mar-18 10:49 
AnswerRe: Move Up And Down rows in datagridview and update it in database Pin
Eddy Vluggen2-Mar-18 12:34
professionalEddy Vluggen2-Mar-18 12:34 
GeneralRe: Move Up And Down rows in datagridview and update it in database Pin
Member 133258462-Mar-18 23:53
Member 133258462-Mar-18 23:53 
GeneralRe: Move Up And Down rows in datagridview and update it in database Pin
Eddy Vluggen3-Mar-18 2:34
professionalEddy Vluggen3-Mar-18 2:34 
GeneralRe: Move Up And Down rows in datagridview and update it in database Pin
Member 133258463-Mar-18 18:47
Member 133258463-Mar-18 18:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.