Tuesday, January 31, 2006

Display a Windows Form without Recreate the Object

This is a simple code to check whether a form is already created or not.
First, if the Form is nothing then we always create the object.
Second, if the form is ever created but already disposed. The objForm contains a reference but the objForm.Created is false. We also create the object.
Otherwise, we only show and activate the form without recreate the object if the form is already created.

Private objForm as myFormName

Private Sub DisplayForm()
   If IsNothing(objForm) OrElse Not (objForm.Created) Then
      objForm= New myFormName

   End If
   objForm.Show()
   objForm.Activate()

End Sub

No comments: