本文介绍了如何防止多个子窗体打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个MDI应用程序。在菜单上,从其中一个菜单中选择子项表单 。我不想玩禁用/启用菜单项 游戏。我选择将开放表格添加到窗口中。菜单项。 我正在寻找的是当用户点击菜单项打开 表格时,我该如何查看它是否'' s已经打开,如果是,那么设置 焦点(如果可能的话)。 现在发生的事情是菜单项被点击2,3或甚至4次,它每次都会打开表单的新实例。 我可以在此代码中更改哪些内容可以打开我的子表单以防止它出现 打开新实例? Dim frmCustomers作为新客户() frmCustomers.MdiParent = Me frmCustomers.WindowState = FormWindowState.Maximized frmCustomers.Show() 谢谢, Tony 解决方案 例如,您可以使用变量来保存表单实例。对于 的例子, 私人frmCustomers作为客户 私有子mnuShowCustomers_Click() 如果frmCustomers没什么OrElse frmCustomers.IsDisposed那么 frmCustomers =新客户() frmCustomers.MdiParent =我 结束如果 frmCustomers.WindowState = FormWindowState.Maximized frmCustomers.Show() End Sub I have a MDI application. On the menu toolstrip child forms are selectedfrom one of the menus. I don''t want to play the disable/enable menu itemgame. I have selected that open forms are added to the "Window" menu item.What I''m looking for is when the user clicks on the menu item to open theform, how can I check to see if it''s open already and if so then set thefocus (if possible). What happens now is if the menu item is clicked on 2, 3 or even 4 times, itopens new instances of the form each time. What can I change in this code that opens my child forms to prevent it fromopening new instances? Dim frmCustomers As New Customers()frmCustomers.MdiParent = MefrmCustomers.WindowState = FormWindowState.MaximizedfrmCustomers.Show()Thanks,Tony 解决方案 You could, for example, use a variable to hold the form instance. Forexample, Private frmCustomers As Customers Private Sub mnuShowCustomers_Click()If frmCustomers Is Nothing OrElse frmCustomers.IsDisposed ThenfrmCustomers = New Customers()frmCustomers.MdiParent = MeEnd IffrmCustomers.WindowState = FormWindowState.MaximizedfrmCustomers.Show()End Sub 这篇关于如何防止多个子窗体打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-18 11:29