i want to prevent a form from closing..
to do this i want to handle the formClosing or FormClosed events.
from here i want to prevent the form from closing.
New instance of same form should not be used.
is there any way to do this?
is it posiible to do the same thing with anycode?
On your form load code, loop through all open windows to make sure
another instance isn't already open.
If it is, just switch focus to it and abort opening this window.
For Each openWindow As Form In Application.OpenForms
If (openWindow.GetType() = Me.GetType()) Then
'duplicate instance. Send focus to the already
open window
openWindow.Focus()
'abort opening me
Close()
End If
Next
that's one way. The other way is obviously
dim openWindow as form
instead of the button / event saying:
dim frm as new Form1
frm.show()
you could declare frm as a member variable instead of a method
variable, that way you can tell if the window is already open.
dim frm as new Form1 '<-- declared at top of file
'in code
if (frm IsNot Nothing) then
frm = new Form1()
frm.show()
end if
frm.Focus()
but you have to remember to mark it as Nothing when the window is
closed which isn't always easy if the window can be opened from
multiple places. Probably use a global variable for that scenario.
Phill