I want to pass values between two Forms (c#). How can I do it?
I have two forms: Form1 and Form2.
Form1 contains one button. When I click on that button, Form2 should open and Form1 should be in inactive mode (i.e not selectable).
Form2 contains one text box and one submit button. When I type any message in Form2's text box and click the submit button, the Form2 should close and Form1 should highlight with the submitted value.
How can i do it? Can somebody help me to do this with a simple example.
You can use this;
Form1 button1 click
And add this to Form2
Form2 button1 click
Form1 Code :
Form2 Code :
It Works!
This is very simple. suppose you have 2 window form Form1 and Form2 and you want to send record of textbox1 from Form1 to Form2 and display this record in label1 of Form2; then in Form2 create a label which name is label1 and go to the property of label1 and set 'Modifiers'=public and in Form one create a textBox with id textBox1 and a button of name submit then write the following code on button click event
thats it... for this way you can bind dataset record to another form's datagridview......
Constructors are the best ways to pass data between forms or Gui Objects you can do this. In the form1 click button you should have:
In form 2, when the user clicks the button it should have a code like this or similar:
Once inside the form load of form 1 you can add code to do anything as you get the values from constructor.
How to pass the values from form to another form
1.) Goto Form2 then Double click it. At the code type this.
2.) Goto Form1 then Double click it. At the code type this. //At your command button in Form1