如何在不创建新实例的情况下从另一个子窗体启用子窗体中的按钮 [英] How to enable a button in a child form from another child form without creating a new instance

查看:70
本文介绍了如何在不创建新实例的情况下从另一个子窗体启用子窗体中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好codeproject我有一个带menustrip的mdi应用程序,该应用程序有两个下拉菜单项,其中一个下拉菜单项链接到一个表单,可以说form2.i也有一个登录表单,我希望每当用户使用特定的登录名登录时角色,应该启用form2中的按钮,而无需创建form2的新实例.但是,如果您单击form2菜单项,您应该注意到form2 haz bin中的按钮已启用

感谢evryone的帮助.

Hello codeproject I have an mdi app with menustrip that has two drop down items one of the drop down item links to a form lets say form2.i also have a login form ,i want that whenever a user logs in with a particular role , a button in the form2 should be enabled witout creating a new instance of the form2. But if you click on the form2 menustripitem you should noticed that the button in the form2 haz bin enabled

thanks evryone for your help.

推荐答案

处理此问题的最佳方法是通过MDI Parent.

您的登录表单(假设它是MDI子级)应该创建一个事件,该事件由父级处理:例如LoginStatusChanged.
然后,父级通过一个或多个公共属性从登录表单中读取登录信息,并根据需要再次通过公共属性将其传递给其他MDI子级.

然后,每个单独的孩子都会在属性更改时查看新状态,并将其菜单,工具栏和其他控件设置为适当的状态.

这种方法的优点是,任何形式都不需要知道其他形式的存在(父形式除外,但是由于它创建了子形式,因此是允许的).

如果您不知道该怎么做,请问!
The best way to handle this is via the MDI Parent.

Your login form (assuming it is a MDI Child) should create an event, which the parent handles: LoginStatusChanged for example.
The parent then reads the login information from the login form via one or more public properties and passes it as necessary to the other MDI children, again via public properties.

Each individual child then looks at the new status when the property changes and sets it''s menus, tool bars, and other controls to the appropriate state.

The advantage of this approach is that no form needs to know about the existence of the others (except the parent, but since it creates the children, that''s allowed)

If you don''t know how to do any particular part of this, just ask!


这篇关于如何在不创建新实例的情况下从另一个子窗体启用子窗体中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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