Groups | Blog | Home
all groups > visual studio .net general > may 2007 >

visual studio .net general : Static second form disposed


Carlos Sanchez
5/23/2007 5:54:01 PM
Thi should be very simple but I'm having problems with it, i want to
display a non modal static second form. When I say 'static' I mean
contents should not be lost when hidden.

So i have my Form2 class form declared in Form1 like:

public static Form2 form2 = null;

And then I have:

private void button1_Click(object sender, System.EventArgs e)
{
if (form2 == null) form2 = new Form2();
form2.Show();
}


Well, frist time I press button form is shown, then I press the the
close button (the X in the corner) and when I try to show it again it
says it has been disposed.

Same code with ShowDialog works fine, but somehow when I close the
second form it gets disposed if I use Show(). I cannot use ShowDialog
cause I want both main and second form to be avaliable at the same time.

Bryan Phillips
5/23/2007 6:52:30 PM
Add an event handler to the form's Closing event, cancel the close and
execute this.Hide(); instead.

--
Bryan Phillips
MCT, MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com
Web Site: http://www.composablesystems.net



[quoted text, click to view]
Carlos Sanchez
5/24/2007 1:12:30 AM
[quoted text, click to view]

AddThis Social Bookmark Button