How close down parent form after creating new form

G

Guest

What I have is a menustrip and inside the click event is

dim t as new form2
t.show

'We are in form1
me.close

and while it shows form2 I want to close the form where the call is coming
from. In this instance the form1 is where the user is clicking the menu item.
But for some reason I can't get this to work. It seems simple but I can't
figure it out. What happens is when I call me.close on form1 it closes form2.

What I'm trying to accomplish is something like what we are doing in our
existing asp app that we are trying to convert to windows form .net 2005 app.
We have frames and in the top frame we have all our links and when a user
clicks on one it repopulates the main frame only.

Now I know I can't do this in windows but I trying simulate something like
that where they click on a menu item and the new screen pops up and the
previous screen disappears all at once.

ANy help would be appreciated.
 
R

Robbe Morris [C# MVP]

Try this in the click event. I yanked this out of an old
..NET Compact Framework app.

MyForm newform = new MyForm();

this.SendToBack();
this.Enabled = false;
newform.Show();
this.Close();

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/adonet_source_code_generator.asp
 
L

Linda Liu [MSFT]

Hi Master,

Based on my understanding, you have a WinForms application, which has a
form1 with a menustrip on it. When the user clicks on one menustrip item
from the form1, a new form2 is shown. You want to close the previous form1
while showing the new form2. However, what happens is when you close the
form1, form2 is closed as well. If I'm off base, please feel free to let me
know.

Is form1 the startup form in your program? If so, when you close the
startup form, all forms that have been opened in the program will be
closed and the application will exit. If form1 is not the startup form, you
could open a new form2 from it and close the form1(the new form2 won't be
closed at this instance).

I think there are two options for you to do what you want to do.
Option 1: Don't make form1 the startup form of your program. You could use
MDI frame in the program and open form1 as an MDI child.
Option 2: After you open the new form2 from the form1, don't close the
form1 but instead hide it (you could call the Hide method of the form1 to
hide it). Note that if the form1 is the startup form and you hide it after
you open a new form2 from it, the application won't exit after you close
the form2(unless you call Application.Exit in form2).

Hope this helps.
If my suggestions aren't what you want, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top