I have a user control, it must set a property when it is just created, so I set it in its constructor, which has an parameter to specify the property .
For example:
public class ExecQuest : UserControl,IOleClientSite,IDocHostUIHandler
{
public ExecQuest(Type showType)
{
this.showType = showType;
}
}
Becuse showType property should not have default value and must be set at the begining, I don't want the user control class has default constructor with no arguements.
But When I put a user control on a form, seems auto-generated code in InitializeComponent() {} use control's default constructor.
I can only manually change code in InitializeComponent(), which ruined if I go to design mode and InitializeComponent() generated again.
public class frmExecute : System.Windows.Forms.Form
{
private void InitializeComponent()
{
this.EQ = new ExecQuest(Type.Builder); // manyally edited, it was this.EQ = new ExecQuest()
}
}
What is better way solve this problem?
In other words,
a.. What is mechanism for generating InitializeComponent(){}?
b.. How to use a user control's constructor which has parameters in design view mode in Visual Studio 2003?
Thanks a lot!
Ryan