form1 and form2

  • Thread starter Thread starter james ou
  • Start date Start date
J

james ou

Hi,

I create a form2 in the form1. Can I change some data
of form1 in the form2?

Thanks
 
Maybe its better to show your source code first,so we can grasp your meaning
better.
 
Yes. One way is to set the Modifiers property of any control you want to
access on form1 to Internal or Public. Make sure you pass a reference to
form1 into form2, then, for example, use the line:
form1.TextBox1.Text = "NewText";
Tom Clement
 
In the form1, have a button to be clicked to create form2,
and in the form2, have a textbox to let user input some
data.Is there some way to let the form1 receive the input
data or to change some variable(data) in the form1 after
user input some data in the form2?
 
Maybe something like this (in C#):

In form2 -- start code --

private form1 m_frmForm1;
internal form1 MyForm1 {set { m_frmForm1 = value;}}

.....
{
...
m_frmForm1.TextBox1.Text = "New Text";
}

form2 -- end code --

now in form1 -- start code --
.....
form2 myForm2 = new myForm2();
myForm2.MyForm1 = this;

form1 -- end code --
 
Back
Top