TM80 TM80 - 6 months ago 34
Vb.net Question

Form Activated event and messagebox causes unwanted looping

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)

Answer

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