Reputation: 870
I would like som help to close form1 as you open form2.
Form2 myForm = new Form2();
myForm.Show();
I would like to know how to communicate between forms, like sending integers between?
Thanks!
Upvotes: 0
Views: 84
Reputation: 46728
There are several ways you could do that. See this, it lists 4 ways you could go about doing just that...
Upvotes: 2
Reputation: 1665
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.
Upvotes: 0
Reputation: 15378
Form2 myForm = new Form2(this);
myForm.Show();
constructor Form2:
Window _parent;
void Form2(Window parent)
{
_parent = parent;
}
and use _parent
Upvotes: 0
Reputation: 8201
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)
Upvotes: 4