Shifting around forms.

  • Thread starter Thread starter SiewSa
  • Start date Start date
S

SiewSa

Actually, I am having this problem long time ago. It applies to both of my
VB.NET programming and the Compact Framework.

Like what we can do last time in VB6....instead of closing a form, we can
temporarily hide a form and shift to another form. After that, we can get
back to that old created form easily by asking it to show.

However, this seems not to be the situation to me in .NET framework. I
don't know how to refer back to a old created form instance. To create a
new instance, I will:

Dim frmTest as New frmTest
frmTest.Show

How about not to close an instance and to refer back to that instance? I am
very grateful to someone out there who is willing to help me on this. Thank
you.
 
Make sure of two things:

1. The local variable (frmTest) doesn't go out of scope. You should use a
member variable, not a method variable.
2. The Form doesn't get closed, but instead only hidden. If you've got an
(OK) button in the upper right at run time then it's getting closed and
disposed. You need to override the onclosing event or set the MinimizeBox
to true.

-Chris
 
First of all, thanks for the reply.

However, could you please explain a bit more on that? What do you meant by
to use member variable instead of method variable? What are member variable
and method variable actually?

Secondly, yes, I do override the closing event and deny the forms from
closing. However, how am I going to refer back to that form by code later
on?

example:
Dim frmTest As New frmTest
frmTest.Show
......
.....
.....(after some other codes...and get out of the sub, but in the same
class)..
frmTest.xxxx
The system seems not knowing frmTest anymore. What should I do then?

Thanks in advance on your further explanations. Sorry for my insufficient
knowledges.
 
A member variable is a variable accessibly anywhere in the class. A method
variable is one available in a method.

Here's a rudimentary, not guaranteed to even compile, example that gives you
an idea....

class Foo
{
private formB = new MyForm();

void ShowA()
{
MyForm formA = new MyForm();
formA.Show();
}

void ShowB()
{
formB.Show();
}

void TestShow()
{
// here we can show A only through the ShowA method.
// Once shown we still can't reference it
ShowA();

// here we can show B through the method or member variable
ShowB();
// we can also do whatever we want with it
formB.Text = "I was done right!"
}
}
 
Back
Top