Passing data between forms
-
Looking for code to pass information from Form2.textbox1 back to Form1.label1 Process - Press Form1.button1 to show Form2, Enter information into Form2.textbox1, Press Form2.button1 to display information from Form2.textbox1 to Form1.label1. Thnaks in Advance! Form1 consists of Label1 Button1 For2 consist of textbox1 Button1
-
Looking for code to pass information from Form2.textbox1 back to Form1.label1 Process - Press Form1.button1 to show Form2, Enter information into Form2.textbox1, Press Form2.button1 to display information from Form2.textbox1 to Form1.label1. Thnaks in Advance! Form1 consists of Label1 Button1 For2 consist of textbox1 Button1
Pass an instance of
Form1
to constructor of Form2 when instanciating, something like this:Form2 frm2 = new Form2(this);
Then in
Form2
, you have access to all public and internal variables ofForm1
, so you can define a property of your Lable1 in Form1:public string MyLable{
get{
return this.Lable1.Text;
}
set{
}
this.Lable1.Text = value;
}and in
Form2
, when the user clicks onButton1
, do this:frm1.MyLable = TextBox1.Text;
frm1
is a variable of typeForm1
that holds a refrence toForm1
which has been passed to constructor of Form2. abcdabcdabcdabcda Don't forget, that'sPersian Gulf
not Arabian gulf!
Why do we close our eyes, when we dream?, When we cry?, When we imagine?, When we kiss?, Its because the most beautiful things in the world are unseen
Murphy:
Click Here![^]
I'm thirsty like sun, more landless than wind...
-
Looking for code to pass information from Form2.textbox1 back to Form1.label1 Process - Press Form1.button1 to show Form2, Enter information into Form2.textbox1, Press Form2.button1 to display information from Form2.textbox1 to Form1.label1. Thnaks in Advance! Form1 consists of Label1 Button1 For2 consist of textbox1 Button1
Google on "Mediator pattern" and "MVC" (or "Model-View-Controller"). If you learn how to use these patterns, you'll never get stuck like this again; your code won't need tricks like passing a form to another form. I recommend "Design Patterns" by the Gang of Four. I'm not saying maysam's advice is bad, but as you construct more and more complicated GUIs, you'll find that it's harder and harder to deal with the complexity you create by hard-wiring things together. Design patterns are over-applied and otherwise screwed up by morons who haven't taken the time to really learn how to use them, which has given them a bad rap. In my experience, though, Mediator and MVC are the most important things to know when programming client-side rich GUI applications. Everything else is a little bit of learning involving threads that's easy to accomplish, and rote memorization of properties of controls and the like.