简体   繁体   中英

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.
Is it possible to find loaded form controls in class library?

Form.Controls property is what you need.

You can pass the reference of your form into your library, and access its controls via Controls property.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM