问题描述
我一直在努力使其工作...我在MDIchild表单上有一个按钮可以打开另一个MDIchild表单,但是如果该表单已经打开,它将无法识别并打开一个新的表单而不是把它放在前面.这是我得到的代码:
I've been struggling to get this to work...I have a button on a MDIchild form that opens another MDIchild form, but if the form is already open, it does not recognize it and opens a new one instead of bringing it to front. This is the code i've got:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim MDIForm4 As New Form4
MDIForm4.MdiParent = Me
MDIForm4.Show()
End Sub
这适用于打开新表单的按钮,然后我尝试添加此按钮:
This works for the button to open the new form, and then I tried adding this:
If Not Form4 Is Nothing Then
Form4.BringToFront()
End If
但没有积极的结果.有人有什么想法吗?
But with no positive outcome. Does someone have any ideas?
此致
豪尔赫·布里托
推荐答案
以下是我通常的做法:
For Each f As Form In Application.OpenForms
If TypeOf f Is frmTest Then
f.Activate()
Exit Sub
End If
Next
Dim myChild As New frmTest
myChild.MdiParent = Me
myChild.Show()
请注意,此方法使用Application.OpenForms,如果只需要主窗体的子级,则可以使用Me.MdiChildren(假设Me =此MDI窗体).
Notice this uses Application.OpenForms, you can use your Me.MdiChildren (assuming Me = this MDI form) if you want just the children of your main form.
这篇关于如果已经打开,将MDIChild表单放在最前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!