Vb.net Winforms MDI 多个窗体实例打开
Vb.net Winforms MDI multiple instance of form open
我想知道如何在不重复相同实例的情况下在MDI父窗体中打开多个窗体?
例如:License Form和User Form同时打开,不重复。
For Each f As Form In Application.OpenForms
If f.Name = "License" Then
FormOpen = True
f.Focus()
Return
End If
If f.Name = "User" Then
FormOpen = True
f.Focus()
Return
End If
Next
If FormOpen = False Then
If e.Node.Name = "License" Then
Dim license As New License
license.MdiParent = Me
license.Show()
End If
If e.Node.Name = "User" Then
Dim license As New User
license.MdiParent = Me
license.Show()
End If
End If
这是我的代码,但它只能同时打开其中一个表单。有人可以帮忙吗?
使用 Exit statement instead of a Return.
Exit
语句退出过程或块,并立即将控制转移到过程调用或块定义之后的语句。
Return
语句 returns 控制调用 Function
、Sub
、Get
、Set
或 Operator
程序。
在这种情况下使用 Exit For
。
您可以在模块中声明一个 public 布尔变量,以避免每次打开表单时出现重复。如果您成功打开该变量存储 "True" 值的表单;如果不这样做,它会存储错误。您还必须将 "False" 存储到每个表单的 Closed 事件中的变量。
下面是源码:
Private Sub MDIParent1_Load(sender As Object, e As EventArgs) 句柄 MyBase.Load
User.MdiParent = 我
License.MdiParent = 我
结束子
Private Sub OpenLicenseAndUserFormsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenLicenseAndUserFormsToolStripMenuItem.Click
If bool = True Then
Exit Sub
End If
Try
For Each f As Form In Me.MdiChildren
If f.Name = "License" Then
Dim frm As New License()
frm.MdiParent = Me
frm.Show()
End If
If f.Name = "User" Then
Dim frm As New User()
frm.MdiParent = Me
frm.Show()
End If
bool = True
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
我想知道如何在不重复相同实例的情况下在MDI父窗体中打开多个窗体? 例如:License Form和User Form同时打开,不重复。
For Each f As Form In Application.OpenForms
If f.Name = "License" Then
FormOpen = True
f.Focus()
Return
End If
If f.Name = "User" Then
FormOpen = True
f.Focus()
Return
End If
Next
If FormOpen = False Then
If e.Node.Name = "License" Then
Dim license As New License
license.MdiParent = Me
license.Show()
End If
If e.Node.Name = "User" Then
Dim license As New User
license.MdiParent = Me
license.Show()
End If
End If
这是我的代码,但它只能同时打开其中一个表单。有人可以帮忙吗?
使用 Exit statement instead of a Return.
Exit
语句退出过程或块,并立即将控制转移到过程调用或块定义之后的语句。
Return
语句 returns 控制调用 Function
、Sub
、Get
、Set
或 Operator
程序。
在这种情况下使用 Exit For
。
您可以在模块中声明一个 public 布尔变量,以避免每次打开表单时出现重复。如果您成功打开该变量存储 "True" 值的表单;如果不这样做,它会存储错误。您还必须将 "False" 存储到每个表单的 Closed 事件中的变量。
下面是源码:
Private Sub MDIParent1_Load(sender As Object, e As EventArgs) 句柄 MyBase.Load User.MdiParent = 我 License.MdiParent = 我 结束子
Private Sub OpenLicenseAndUserFormsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenLicenseAndUserFormsToolStripMenuItem.Click
If bool = True Then
Exit Sub
End If
Try
For Each f As Form In Me.MdiChildren
If f.Name = "License" Then
Dim frm As New License()
frm.MdiParent = Me
frm.Show()
End If
If f.Name = "User" Then
Dim frm As New User()
frm.MdiParent = Me
frm.Show()
End If
bool = True
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub