I’m trying to make a TextBox with a button on the right side.
My code:
public partial class TextBoxButton : TextBox
{
[Category("Button")]
[Description("Button in textbox")]
public Button Button
{
get
{
return this.btn;
}
set
{
this.btn = value;
}
}
protected override void OnCreateControl()
{
if (!this.Controls.Contains(this.btn))
{
this.Controls.Add(this.btn);
this.btn.Dock = DockStyle.Right;
}
base.OnCreateControl();
}
}
Everytime when I start my appi and set some text or image in the button it’s empty. Some ideas?
Best regards.
You have to tell the designer that it should also serialize the properties of the button:
The default is Hidden so none of the button properties would be written to the Designer.cs file. Setting, say, the Text property works in the designer but the property value is lost after you start the app or reload the form.