I have created a WindowsFormControlLibrary porject. It works fine, I can drop it on the forms,call its methods,etc …
but now as a property of it, I am passing the name of a Label to it. and I want this custom control to be able to use that label name and for example change its font to bold .
so the question is that if I have a WinForm and I have a Label on that form and my custom control on that form, then how can I tell my custom control to do something with that label which I am passing its name to it?
I have created a WindowsFormControlLibrary porject. It works fine, I can drop it on
Share
First, if you wish to access a
Controlfrom yourUserControl, you will need to use theFindForm()method.Second, you will be required to expose your
TextBoxcontrol, for example, through a property of your form.Then, you would need to know the type of this
Formreturned by thisFindForm()method.Once you know it, you need to type-cast this result to the correct type.
So, here a sample untested pseudo-code to give you the idea:
Then, assuming you have dropped your control on your form, your
UserControlcould have a property like so: