Managing Forms Display

stevecking

Active member
Joined
Dec 27, 2006
Messages
32
Programming Experience
5-10
I've a rather simply request but can't find the elegant solution. I want to be able to determine if a form is already open so another instance of the form isn't opened. If it's not open simply show it but if it is open I want to make it visible. I am aware that I can loop through the My.Application.OpenForms collection but I would assume that millions of developers would want this functionality and the the .NET 2.0 libraries supported it.

Form1 is open
Open Form2 and make Form1.Visible = False

Form2 is opened but being closed
If Form1 is open but not visible then
set the visible property to true
Else
Else open Form1
End If
Close Form2
 
.Net 2.0 have default form instances, instead of creating a New Form1 for example you can just write Form1.Show(), if it is closed a new one is created automatically when you call it.
 
I've just discovered that using form1.show with redisplay the correct form as would visible = true unless I'm using separate instances, which I was doing as a carryover from my previous experiences. I had a mental block. This is great; there is absolutely no need for visible = true except for instances.
 
Well, yes there is if you add some info to the "first" default instance from one place and need to preserve it for later. To manage this you have to prevent the "first" to close and instead hide it. If not a "second" default instance is created that is missing the addition info.
 
Back
Top