VB.NET中MDI子窗体问题
我建了个项目,其中MDI子窗体的关闭全是执行.hide操作,但该操作占内存,有没有其他什么方法使被窗体关闭后能再次被打开。
具体该怎么做?希望最好能有代码,谢谢!
[解决办法]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Form2.Show() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Form2.Close() End Sub
[解决办法]
关闭和hide不一样。
form的show方法,既可以在窗体hide时,或者已经close时,加载该窗体。
代码可以这样写:
Private Sub MDIParent1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Form1.Parent = MdiParent
Form2.Parent = MdiParent
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.Show()
Form2.Show()
End Sub
如果,你关闭了form1和form2,此时你单击button1时,form1和form2都会显示出来,不管是这两个窗体是隐藏的还是关闭的。
[解决办法]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If frm2 Is Nothing OrElse frm1.IsDisposed Then
frm2 = New Form2
With frm2
.MdiParent = Me
End With
End If
frm2.Show()
End Sub