[英]Accessing windows applications controls from class library c# windows application
i wanted to disable form control from class library, means i added one class named as clsInit method & i called this method when i'm loading the form in main project,so i need find the control which one i wanted to disable. 我想从类库中禁用表单控件,这意味着我添加了一个名为clsInit方法的类, 并且在主项目中加载表单时调用了此方法,因此我需要找到我想禁用的控件。
Is it possible to find loaded form controls in class library? 是否可以在类库中找到已加载的表单控件?
Form.Controls
property is what you need. 您需要
Form.Controls
属性 。
You can pass the reference of your form into your library, and access its controls via Controls
property. 您可以将表单的引用传递到库中,并通过
Controls
属性访问其控件。
You may create an object of your form, as: 您可以创建表单对象,如下所示:
MyForm frm = new MyForm();
...then select the controls to be disabled: ...然后选择要禁用的控件:
foreach (Control control in frm.Controls)
{
if(control.Name == "cboSomeDdn")
control.Enabled = false;
}
and then load the form (this one : 然后加载表单(此表单:
frm.Load()
or 要么
frm.Show()
If this is a one form application, you may also set this as a starting point: 如果这是一个表单应用程序,则还可以将其设置为起点:
Application.Run(frm);
Please use this answer as a starting point and not as a copy-paste solution.
请使用此答案作为起点,而不是复制粘贴解决方案。 Also ensure to follow best-practices of development in the language of your choice.
还请确保遵循您选择的语言的最佳开发实践。
Hope this helps! 希望这可以帮助!
Vivek 维维克
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.