C#, need some help with changing form
I would like som help to close form1 as you open form2.
开发者_StackOverflowForm2 myForm = new Form2(); myForm.Show();
I would like to know how to communicate between forms, like sending integers between?
Thanks!
form1.Close();
myForm.Show();
For second question -> forms are just objects. Learn OOP first, and concepts of class variables, properties, constructors etc... Then, use that to pass data between two objects (two forms)
There are several ways you could do that. See this, it lists 4 ways you could go about doing just that...
Forms are just classes. When you say Form2 myForm = new Form2();
you just create a new instance of a class. You communicate to an object (the instance of a class) by calling its methods, setting its properties or raising its events. No magic here.
In particular when you say myForm.Show()
, you have already communicated to the other form. You just didn't realize it. It just so happened, that your Form2 class has had a method called Show, so it worked. But you can create your own methods and call them in the same way.
Form2 myForm = new Form2(this);
myForm.Show();
constructor Form2:
Window _parent;
void Form2(Window parent)
{
_parent = parent;
}
and use _parent
精彩评论