如何防止多个子窗体打开 [英] How to prevent multiple child forms opening

查看:80
本文介绍了如何防止多个子窗体打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MDI应用程序。在菜单上,从其中一个菜单中选择子项表单

。我不想玩禁用/启用菜单项

游戏。我选择将开放表格添加到窗口中。菜单项。

我正在寻找的是当用户点击菜单项打开

表格时,我该如何查看它是否'' s已经打开,如果是,那么设置

焦点(如果可能的话)。


现在发生的事情是菜单项被点击2,3或甚至4次,它每次都会打开表单的新实例。


我可以在此代码中更改哪些内容可以打开我的子表单以防止它出现

打开新实例?


Dim frmCustomers作为新客户()

frmCustomers.MdiParent = Me

frmCustomers.WindowState = FormWindowState.Maximized

frmCustomers.Show()

谢谢,

Tony

解决方案

Tony,


我认为你正在从一个控件中搜索Isdisposed方法(和

因此是表格。
http://msdn.microsoft.com/library/de...posedtopic.asp

Cor

" Tony K" < ki ******** @ NOSPAMcomcast.netschreef在bericht

新闻:4D ********************** ************ @ microsof t.com ...


>我有一个MDI应用程序。在菜单上,从其中一个菜单中选择子表单。我不想玩禁用/启用菜单项
游戏。我选择将开放表格添加到窗口中。菜单项。
我正在寻找的是当用户点击菜单项打开
表单时,如何检查它是否已经打开,如果是,那么设置
焦点(如果可能的话)。


现在发生的事情是菜单项被点击2,3或甚至4次,

它每次都会打开表单的新实例。


我可以在此代码中更改哪些内容可以打开我的子表单以防止它打开新实例



Dim frmCustomers作为新客户()

frmCustomers.MdiParent =我

frmCustomers.WindowState = FormWindowState.Maximized

frmCustomers.Show()


谢谢,

Tony



我可以在这个打开我的子表单的代码中更改什么来阻止它


来自打开新实例?


Dim frmCustomers作为新客户()

frmCustomers.MdiParent =我

frmCustomers.WindowState = FormWindowState.Maximized

frmCustomers.Show()



例如,您可以使用变量来保存表单实例。对于

的例子,


私人frmCustomers作为客户


私有子mnuShowCustomers_Click()

如果frmCustomers没什么OrElse frmCustomers.IsDisposed那么

frmCustomers =新客户()

frmCustomers.MdiParent =我

结束如果

frmCustomers.WindowState = FormWindowState.Maximized

frmCustomers.Show()

End Sub



谢谢你。你已经帮我几次了,我真的很感激

吧。感谢有用的链接。


Tony

" Cor Ligthert [MVP]" < no ************ @ planet.nlwrote in message

news:%2 **************** @ TK2MSFTNGP03.phx.gbl ...


Tony,


我认为您正在搜索Isdisposed方法控制

(因此表格)。
http://msdn.microsoft.com/library/de...posedtopic.asp


Cor


" Tony K" < ki ******** @ NOSPAMcomcast.netschreef在bericht

新闻:4D ********************** ************ @ microsof t.com ...


>>我有一个MDI应用程序。在菜单上,从其中一个菜单中选择子表单。我不想玩禁用/启用菜单项
游戏。我选择将开放表格添加到窗口中。菜单
项目。我正在寻找的是当用户点击菜单项以打开表格时,如何检查它是否已经打开,如果是,那么
设置焦点(如果可能的话。

现在发生的事情是菜单项被点击2,3或甚至4次,
每次都会打开表单的新实例。
<我可以在这个打开我的子表单的代码中更改什么来防止它打开新实例?

昏暗的客户作为新客户()
frmCustomers.MdiParent =我
frmCustomers.WindowState = FormWindowState.Maximized
frmCustomers.Show()

谢谢,
Tony



I have a MDI application. On the menu toolstrip child forms are selected
from one of the menus. I don''t want to play the disable/enable menu item
game. 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 the
form, how can I check to see if it''s open already and if so then set the
focus (if possible).

What happens now is if the menu item is clicked on 2, 3 or even 4 times, it
opens new instances of the form each time.

What can I change in this code that opens my child forms to prevent it from
opening new instances?

Dim frmCustomers As New Customers()
frmCustomers.MdiParent = Me
frmCustomers.WindowState = FormWindowState.Maximized
frmCustomers.Show()
Thanks,
Tony

解决方案

Tony,

I think that you are searching for the Isdisposed method from a control (and
therefore a form).
http://msdn.microsoft.com/library/de...posedtopic.asp

Cor
"Tony K" <ki********@NOSPAMcomcast.netschreef in bericht
news:4D**********************************@microsof t.com...

>I have a MDI application. On the menu toolstrip child forms are selected
from one of the menus. I don''t want to play the disable/enable menu item
game. 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 the
form, how can I check to see if it''s open already and if so then set the
focus (if possible).

What happens now is if the menu item is clicked on 2, 3 or even 4 times,
it opens new instances of the form each time.

What can I change in this code that opens my child forms to prevent it
from opening new instances?

Dim frmCustomers As New Customers()
frmCustomers.MdiParent = Me
frmCustomers.WindowState = FormWindowState.Maximized
frmCustomers.Show()
Thanks,
Tony



What can I change in this code that opens my child forms to prevent it

from opening new instances?

Dim frmCustomers As New Customers()
frmCustomers.MdiParent = Me
frmCustomers.WindowState = FormWindowState.Maximized
frmCustomers.Show()

You could, for example, use a variable to hold the form instance. For
example,

Private frmCustomers As Customers

Private Sub mnuShowCustomers_Click()
If frmCustomers Is Nothing OrElse frmCustomers.IsDisposed Then
frmCustomers = New Customers()
frmCustomers.MdiParent = Me
End If
frmCustomers.WindowState = FormWindowState.Maximized
frmCustomers.Show()
End Sub



Thank you Cor. You''ve helped me out several times and I really appreciate
it. Thanks for the useful links.

Tony
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...

Tony,

I think that you are searching for the Isdisposed method from a control
(and therefore a form).
http://msdn.microsoft.com/library/de...posedtopic.asp

Cor
"Tony K" <ki********@NOSPAMcomcast.netschreef in bericht
news:4D**********************************@microsof t.com...

>>I have a MDI application. On the menu toolstrip child forms are selected
from one of the menus. I don''t want to play the disable/enable menu item
game. 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 the form, how can I check to see if it''s open already and if so then
set the focus (if possible).

What happens now is if the menu item is clicked on 2, 3 or even 4 times,
it opens new instances of the form each time.

What can I change in this code that opens my child forms to prevent it
from opening new instances?

Dim frmCustomers As New Customers()
frmCustomers.MdiParent = Me
frmCustomers.WindowState = FormWindowState.Maximized
frmCustomers.Show()
Thanks,
Tony



这篇关于如何防止多个子窗体打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆