views:

62

answers:

2

When you drag a new Button onto a Windows Form it is automatically assigned the text "button1". If you have a control that inherits button called "CustomButton" then that one is automatically assigned the text "customButton1" when added to a form.

Is it possible to make this text default to something else? For example, can I have the text default to "click me!" when the control is dragged onto a form?

A: 

The simplest way to do this would be to not use the standard Text property and make your own instead.

If you do that, you should override the Text property and apply [Browsable(false)].

SLaks
Thanks, that's exactly what I ended up doing with a new property called ButtonText.
Sean Gough
A: 

Have you tried to set the Text property in your derived control's constructor?

public CustomButton() {
    Text = "Click me!";
}

If you also want your text to appear as real default value (i.e. not bold in the property window), you should override the Text property and set a DefaultValue-Attribute:

[DefaultValue("Click me!")]
override string Text {
    get { return base.Text }
    set { base.Text = value; }
}
MartinStettner
I don't think this will help.
SLaks
I tried something along these lines before posting and it seems as long as the property was called Text something overrode it's value when added to a form.
Sean Gough