MDI Child Form Has Single Instance
When working on Windows form application a found that the MDI child form is not singleton as a class cannot have a only single instance by default. I search Internet and found so Technical notes on it and the solution well how good they are is know clear to me. I have my own method of doing the same.
The method goes as ...
Declare a Class instance in your form as local member or any type in MDI class like.. (in VB.NET)
class MyMDIForm
{
Dim myChild as new frmChild 'Can also be initialize in form load
Form_Load()
{
myChild.parent=Me
}
...other code
}
Than in the frmChild form in add these two lines in form's closing module
class frmChild
{
Private Sub Form_Closing(..., ByVal Cancel as...) handles MyBase.Closing
{
Me.hide()
Cancel=False
}
...other code
}
Quit Simple..
Now in you menu click event in MDI form just use
myChild.show()
That it is...
Though it has one Bug So far...
That when ever your all child form are open it will not close the application so you have to take care of it... I will add that code soon
Till than bye
Sumit Gupta
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home