I've created new User Control inherited from Button and i set Text property value to " ", but when I place my control on a form it has Text equal to control name.
How can I prevent changing Text property of my control
i don't think what you are trying to do is good thing because if your control text always " " that will confuse you if you added 2 controls of the same type anyway
creat a new class copy and past this code
class Class1 : System.Windows.Forms.Button
{ string defaultText = " "; public override string Text { get
{ return " "; } set
{ defaultText = value; } } }
then press ctrl+shift+B , you will find this control in your tool box drag it to your form
note in get statment you can't change it to variable if you did the instance will take the class name again
user control have some extra code for designer than inhertance from a class, anyway, i don't think you will use the help button 100 times , and its always easy to change the button text , and remember the editor for you not for your client , you can change the text in properties or make a control for that , its handy for you .
to show this property in properties or to hide it is a different issue has nothing to do with what you want to do
Default Text property in User Control
fivefinger
Text property is set to " ", but after placing on the form it is replaced by control name :( .
stefansve
The idea of creating this button is to make help button (thats the reason of constant " " in the text).
In your solution user can't change text if he want but I want to have button with default value with change option, but your idea can be helpfull.
I found another way:
Will Durning
this code isn't a user control , its a class
i don't think what you are trying to do is good thing because if your control text always " " that will confuse you if you added 2 controls of the same type anyway
creat a new class copy and past this code
class Class1 : System.Windows.Forms.Button {
string defaultText = " ";
public override string Text
{
get {
return " ";
}
set {
defaultText = value;
}
}
}
then press ctrl+shift+B , you will find this control in your tool box drag it to your form
note in get statment you can't change it to variable if you did the instance will take the class name again
hope this helps
Phatsuo
hi,
user control have some extra code for designer than inhertance from a class, anyway, i don't think you will use the help button 100 times , and its always easy to change the button text , and remember the editor for you not for your client , you can change the text in properties or make a control for that , its handy for you .
to show this property in properties or to hide it is a different issue has nothing to do with what you want to do
hope this helps
Cameron T
Try this-
public
class ButtonEx : Button{
string m_text;
public string Text{
get { return m_text; } set { m_text = value; }}
public ButtonEx(){
base.Text = " ";}
}
Hope this helps