通用开放式函数
有人写过通用的“LaunchForm”函数吗?对于我打开表单的所有菜单项,我想编写一个函数来启动表单,而不是多次编写相同的代码。
任何提示都会非常有帮助。
这是 winforms + vb.net
谢谢 TR
has anyone written a generic "LaunchForm" function? For all the menu items I have that open a form, I would like to write one function that will launch the form as opposed to writing the same code several times.
any tips would be very helpful.
It's winforms + vb.net
thanks
TR
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的意思是这样的吗?
C#
VB.NET
You mean something like this?
C#
VB.NET
您可以将表单类型附加到菜单项的 .Tag 属性。将单个事件处理程序连接到所有菜单项单击事件,并将 .Tag 属性值(表单类型)传递给创建新实例并显示它的函数。
或者,如果每个表单都是单例,您可以创建一个(MenuItem,Form)字典,预填充表单实例并进行适当的查找/显示。或者甚至跳过字典并弹出表单实例到菜单项的 .Tag 属性中。
有各种各样的选择,在不知道预期用途的情况下,很难只推荐一种。
You could attach the form type to the menuitem's .Tag property. Hook up a single event handler to all the menu item click events and pass the .Tag property value (form type) to a function that created a new instance and displayed it.
Alternately, if each form is to be a singleton you could create a dictionary of(MenuItem, Form), prepopulate with form instances and do the appropriate lookup/show. Or even skip the dictionary and pop and instance of the form into the menuitem's .Tag property.
There's all kinds of options and without knowing the intended usage it's hard to suggest just one.