Method One
may not be practical, just for simple projects:
Dim frmtmp as Classform "Implementation has designed a form called (class name) Classform
frmtmp = New Classform "Defines an instance of it here
Frmtmp.showdialog () is displayed as a modal form
This allows the menu buttons on the other form to be unavailable until the current form is closed, which avoids multiple instantiation problems.
Method Two
Applies only to situations where the form is not particularly numerous, and when there is no special requirement for multiple runtime memory usage
When the project is run, define each instance of the form that may be used, but do not display it, only when it needs to be displayed, X.show (x is the name of the form instance that you want to show), and use x.hide when you close it.
Method Three
Define the global variables for each form class that you want to display, and use the following code before you actually display the form:
If frm is nothing OrElse frm. Isdisposed Then
frm = New Form1
frm. Show ()
Else
frm. Activate ()
End If
Method Four
This method is especially useful for multiple document interfaces:
Dim Frmtmp as Form
"Search for each MDI child form will not be too many subforms open, so there is no speed problem
For each frmtmp in Me.mdichildren
"If find the Classfrm form you want to display
If TypeOf frmtmp is classfrm Then
Frmtmp.activate ()
Exit Sub
End If
Next
"If the form you want to display is not in the MDI child form
The new instance is defined and displayed.
Frmtmp = New ClassFrm400
Frmtmp.mdiparent = Me
Frmtmp.show ()
In the project, because of the TreeView effect, making the traditional method impossible to implement the subform at the top, for a long time, and finally used. ShowDialog () to achieve.