user310291
user310291

Reputation: 38228

Can I set the value of a custom control programmatically in control project designer?

Let's say I have a label in a custom control. In the constructor I set it's text value.

The label doesn't refresh. It does so only when in a client form.

How can I update this label on the custom control itself programmatically ?

Upvotes: 0

Views: 116

Answers (1)

Edwin de Koning
Edwin de Koning

Reputation: 14387

Make the text of the label accessible as a property of the Control: (The getter is not necessary for your case, so you can leave that out if you don't want it)

public string LabelText
{
   get
   {
       return Label1.text;
   }
   set
   {
       Label1.text = value;
   }
}

This way the property will even show up in the designer of the control, or you can set it programmatically lik this:

MyControl.LabelText = "text";

Upvotes: 2

Related Questions