Reputation: 225
I have designed some custom controls to use with a toolstrip, and therefore I have subclassed ToolStripControlHost. In this case a checkbox... My code looks like this:
public class ToolStripCheckBox : ToolStripControlHost
{
public ToolStripCheckBox()
: base(new CheckBox())
{
}
public CheckBox CheckBoxControl
{
get
{
return Control as CheckBox;
}
}
}
When I type them in my Form1.Designer.cs
file they work fine, but when I make modifications in the designer, some of my custom code disappear from Form1.Designer.cs
, more specifically the Event handlers and the custom appearances. For instance this line disappears
this.boldCheckBox.CheckBoxControl.Appearance = System.Windows.Forms.Appearance.Button;
It's a little annoying, and I have no clue what to do :-(
Upvotes: 0
Views: 523
Reputation: 4854
The Form1.Designer.cs is maintened by the Designer and should not be altered. Such tasks are to be performed in the Constructor for your Form1, in Form1.cs, right after the "InitializeComponent" function (It even says // TODO: Add initialization code here
or something like that).
Alternatively, you can code your custom control with full design-time support.
Upvotes: 7
Reputation: 942438
This code doesn't belong in the Designer.cs file, the designer will eat it. It doesn't belong in the form source code file either, only code relevant to the form class should be written there. Project + Add Class. It gets automatically added to the toolbox after you compile.
Upvotes: 1