Reputation: 727
I have created a customize windows form and I just don't know how should I set properties to it.
for example I've created a form with a progress bar, button, and a label and want to set the text of the label, the value of the progress bar, and to get access to the buttonClick Event method form the windows form application that uses the control.
In other words just get access to all the default properties of each control inside.
Is it possible? and how should I do it?
thanks very much!
If I want to to get access to the buttonClick Event method how should I do it?
Upvotes: 0
Views: 796
Reputation: 499382
You need to cast from Control
to the type of your custom control before you can access the properties you have defined.
var myCtrl = (MyControl)controlRef;
myCtrl.MyProperty = xxxx;
This code assumes that MyProperty
has been declared as public
.
Upvotes: 1
Reputation: 331
If I understand your question correctly, you want to expose controls on a form to outside code. One way to achieve this would be to declare accessible properties on the form, for example:
public ProgressBar MyProgressBar
{
get { return progressBar1; }
}
If you wish to only expose certain properties of the controls, you could also have properties that access these directly, like so:
public int MyProgressBarValue
{
get { return progressBar1.Value; }
set { progressBar1.Value = value; }
}
Upvotes: 0