how to open one form from the other form and close the first form

  • Thread starter Thread starter Peter Duniho
  • Start date Start date
P

Peter Duniho

how to open one form from the other form and close the first form if
there are only two forms in windows application(VB.net)

i had tried this method
dim f as new form2
form2.show( )
me.close( )

But, when i run this application both the forms are closing at the
same time

This is a C# newsgroup. If you have questions that don't involve
writing C# code, you should post them elsewhere.

That said, the basic structure of what you posted should work fine, not
counting what appears to be a typographical error in your post.
Calling "f.Show()" should show the second form, and that form should
not close just because you close the current form.

In C# it would look something like this:

class Form1 : Form
{
void SomeMethod()
{
Form2 form = new Form2();

form.Show();
Close();
}
}

And that should work fine.

If you can post C# code that concisely but completely demonstrates the
problem you're having, please feel free to follow up here with that
sample. If you require VB code, then you should post to a VB or
general-purpose .NET programming newsgroup. There still you will want
to post a concise-but-complete sample of code that demonstrates the
problem. The basic idea works fine as you describe so if you're having
trouble getting it to work, you're doing something else that's not
immediately apparent.

Pete
 
how to open one form from the other form and close the first form if
there are only two forms in windows application(VB.net)


i had tried this method
dim f as new form2
form2.show( )
me.close( )



But, when i run this application both the forms are closing at the
same time
 
Peter Duniho said:
This is a C# newsgroup. If you have questions that don't involve writing
C# code, you should post them elsewhere.

That said, the basic structure of what you posted should work fine, not
counting what appears to be a typographical error in your post. Calling
"f.Show()" should show the second form, and that form should not close
just because you close the current form.

In C# it would look something like this:

class Form1 : Form
{
void SomeMethod()
{
Form2 form = new Form2();

form.Show();
Close();
}
}

And that should work fine.

If you have passed a Form instance to Application.Run, the application will
end when that Form closes...

One solution is to use the arg-less version of Application.Run and count
visible forms (ala reference counting).
 
If you have passed a Form instance to Application.Run, the application will
end when that Form closes...

Yup, that's true. The OP never mentioned his application was actually
exiting (seems like that'd be a significant point), so it didn't occur
to me he might be dealing with that situation. But that's probably
just a poorly-formed question...your guess is likely right.

Just goes to show the value of a concise-but-complete sample of code.
:) It's a lot easier to know the specifics when you can see the code.
One solution is to use the arg-less version of Application.Run and count
visible forms (ala reference counting).

The Application.OpenForms property would be a useful source for this
information (as opposed to adding some specific count of forms in a
static variable for example).

Pete
 
Back
Top