MDI 子窗体调用,而不是生成
我有一个 MDI 表单,其中有 3 个嵌套子项。 截至目前,它所能做的就是显示一个新表单。 例如:每次按下菜单按钮时,都会创建新的子表单(Form1)。 现在,如果我再次或随后按下同一菜单按钮,则会创建一个新 Form1,并且它会显示在前一个窗体上。
我想要的是,每次触发事件处理程序(父窗体上的菜单项_单击)时,它不会生成完全“新”的子窗体(弹出一个新窗口),而是会拉出适当的子窗体附在触发器上。
我想这就像重用一个对象一样。
任何帮助将不胜感激。
这是我正在使用的代码示例:
Private Sub RadMenuItem1_Click(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles RadMenuItem1.Click
Dim NewMDIChild As New InventoryForm1()
'Set the Parent Form of the Child window.'
NewMDIChild.MdiParent = Me
'Display the new form.'
NewMDIChild.Show()
I have an MDI form with 3 nested children with in it. As of right now all it can do is display a new form. For example: each time I press the menu button, the new child form(Form1) is created. Now, if I press that same menu button a second or subsequent time a new Form1 is created and it appears over the previous one.
What I would like is that each time the event handler is triggered (a menu item_click on the parent form) that instead of a completely "new" child form being produced(a new window popping up) it would instead pull up the appropriate child form that is attached to the trigger.
I suppose it would be something like reusing an object.
Any help would be greatly appreciated.
Here's the code sample I'm using:
Private Sub RadMenuItem1_Click(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles RadMenuItem1.Click
Dim NewMDIChild As New InventoryForm1()
'Set the Parent Form of the Child window.'
NewMDIChild.MdiParent = Me
'Display the new form.'
NewMDIChild.Show()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您在这里想要的是表单的类级别变量。 类似 -
这样,第一次单击菜单项时,将创建一个新的 InventoryForm1 实例,之后,每次单击菜单项时,将重新打开原始实例。
I think what you want here is a class level variable for the form. Something like -
That way, the first time the menu item is clicked, a new instance of InventoryForm1 will be created, after that, each time the menu item is clicked the original instance will be re-opened.
尝试以下操作(请注意,我有一段时间没有做过 VB .Net,因此语法可能会关闭)
Try the following (note that I haven't done VB .Net in a while, so the syntax may be off)