All,
I’m using MSVS 2010 doing a project with C#/WinForms.
I made an object derived from the group box and I changed it’s constructor so that it will take an integer variable on construction.
I added my object to the toolbox and I can successfully insert that object on the GUI designer.
But every time I make a change in the form my custom constructor is changed.
So I need a way to either fix VS so that every time I changed a form the code won’t rebuild itself or I need some other way of fixing the code in my custom made object.
Basically what I am doing is depending on the parameter I passed I am creating different set of the widgets and show them to the user. But I made that object because I am trying to eliminate the code repetition.
Could someone please help?
Thank you.
The default no-arg constructor must be left in and it should call
InitializeComponents. If that is done, then adding a secondary constructor should be OK and designer should not mess with it.However, I would recommend not using overloaded constructors, but rather exposing Methods or Properties to accomplish the desired task for a WinForms control.
When in WinRome, do as the..
Example of secondary constructor:
Update: avoiding editing the “X.designer.cs” files by hand; these are for the designer. Instead, edit the mirroring “X.cs” file. Partial classes are used to spread up the designer code and your custom code between these two files.