Reputation: 123
I am using an activated event in my vb.net application this is followed by an if statement which causes a messagebox to apear as result of a conditon..
The problem is that the messagebox causes my form to loose focus and then re-activate again everytime the messagebox is clicked resulting in a type of loop which I'm now stuck in how can I get round this?
Private Sub form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
if "EXTERNAL DOCUMENT IS A DRAWING ENVIRONMENT" then
'NOTHING
Else
msgbox("Select drawing environmet first")
me.close()
end if
end sub
The line "EXTERNAL DOCUMENT IS A DRAWING ENVIRONMENT" is a procedure where a variable result returned by autodesk inventor identifying what type of drawing environment is the active document... (this just shortens the whole explanation)
Upvotes: 0
Views: 430
Reputation: 2172
You can use a flag as Malcor says, or you can remove the handler prior to show the Msg, so:
Private Sub form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
if "EXTERNAL DOCUMENT IS A DRAWING ENVIRONMENT" then
'NOTHING
Else
RemoveHandler Me.Activated, addressof form1_Activated
msgbox("Select drawing environment first")
me.close()
end if
end sub
Upvotes: 1
Reputation: 2721
Not Tested. But this may work....
Private WarningShowed As Boolean = False
Private Sub form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
If Not WarningShowed Then
WarningShowed = True
If "EXTERNAL DOCUMENT IS A DRAWING ENVIRONMENT" Then
'NOTHING
Else
MsgBox("Select drawing environmet first")
Me.Close()
End If
End If
End Sub
Upvotes: 0