Add in and regular windows form

401
2
08-23-2011 09:31 AM
JoseSanchez
Occasional Contributor III
Hi all

when I open a windows form from a button loaced in the toolbar how can I hide the form if the button gets clicked again?

I tried that but it does not work, it opens new windwos forms.

Protected Overrides Sub OnClick()
        Dim myForm As frmWindowsForm


        If myForm Is Nothing Then
            myForm = New frmWindowsForm



        End If


        If myForm.Visible Then
            myForm.Hide()
        Else
            myForm.Show()


        End If

        myForm = Nothing


    End Sub
0 Kudos
2 Replies
JeffreyHamblin
New Contributor III
You need to move your form reference outside of OnClick, and not set it to Nothing:

Dim myForm As frmWindowsForm

[in class constructor, set this]
myForm = Nothing

Protected Overrides Sub OnClick()        

        If myForm Is Nothing Then
            myForm = New frmWindowsForm
        End If


        If myForm.Visible Then
            myForm.Hide()
        Else
            myForm.Show()
        End If
End Sub
0 Kudos
JoseSanchez
Occasional Contributor III
It worked thanks!
0 Kudos