Hi,
I have 2 forms , Form1 and Form2. When I click on the "Ok" buttom of the Form 1, it creates an instance of Form2 as below
Form2 newform = new Form2();
newform.Show();
Form2 has a textbox which accepts input from user. I am able to get the Form2 and its textbox, but I am having problems of passing data from Form2 to Form1. Sending data from Form1 to Form2 is not a problem. But here it is the reverse case. How do i pass the data in textbox of Form2 to Form1 ??
Hi,
I have 2 forms , Form1 and Form2. When I click on the "Ok" buttom of the Form 1, it creates an instance of Form2 as below
Form2 newform = new Form2();
newform.Show();
Form2 has a textbox which accepts input from user. I am able to get the Form2 and its textbox, but I am having problems of passing data from Form2 to Form1. Sending data from Form1 to Form2 is not a problem. But here it is the reverse case. How do i pass the data in textbox of Form2 to Form1 ??
Use delegate and events to send info from form2 to form1
Have a look into the attached file....
If you want it to behave like a FileOpen dialog (i.e. stops all input into Form1 until it's closed) use eclipsed4utoo's suggestion but with one change :
DONT MAKE MEMBER VARIABLES PUBLIC
This breaks encapsulation. You should instead have a public property which returns the text in the text box e.g.
Code:
public class Form2 : Form
{
private TextBox _textBox;
public string TextBoxText
{
get
{
return _textBox.Text;
}
}
}
However if you want Form2 to open and stay open whilst the user does things with Form1 then you should use MMH's suggestion of having an event.
Darwen.
www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.