Only one of a form open at a time

Lanc1988

Contributor
Joined
Nov 27, 2003
Messages
508
I have a button that opens another form, but the user can keep clicking the button which causes the same form to open each time. Is there a way to either set a property or enter a code that will only let one of the form be open?
 
The easyest and user friendlyer way its to desable the button when the user ckick it, and re-eanble it when the for is closed...

To desable it's easy, just:
Visual Basic:
button.enable = false

To re-enable it you must declare the form you'll show with WithEvents (in VB.net, in C# isn't necessary).
Visual Basic:
Dim WithEvents Form2 as new Form

On Form1 catch the Closed Event and enable the Button...

There's a way to let the user click the damn button but this way I told you he knows he can't open it no more than once...


If you don't like to desable buttons, you can declare Form2 on a module to make it global, this way, on the button click you can evaluate if Form2 is Nothing, if so its because there's no instance created, if not then an instance is altesdy created.
WIth this last approach you can even bring From2 to the front if it's on a lower z-Order level (behind other forms)...

Alex :p
 
Back
Top