1

The problem is I've already initialized all the initial values for my Properties in my Custom control constructor, for example, PropA = true. But when dragging-n-dropping the final Custom control onto a form, there are some values which are changed to different values (E.g: PropA = false).

I can understand why that happens, that's because of the auto-generated code which do very redundant works. I mean, only properties changed by us (programmers) in the properties window should be added with auto-generated code in the designer.cs files. Why does it have to add redundant code (and sometimes, unwanted code as in my case) to the designer.cs file. Here is the flow of code executing order which makes my default values go away:

public Form(){
   //I replace the InitializeComponent() method by its content right in here
   myCustomControl = new MyCustomControl(); <---- everything is already
   //set up OK at here, no need auto-generated code for my custom properties.

   SuspendLayout();

   /////Initialize properties
   //My custom properties go here, they are already set to default values in my
   //custom control constructor (the line right at the very top above).
   //And that means, all the auto-generated code below are preparing to erase
   //all those default values unexpectedly.

   myCustomControl.PropA = false; //While, PropA is already set to true 
   //in MyCustomControl() constructor and what I want is it should be true, not false
   //but the designer doesn't understand me or I have to understand it????

   //The same for other custom properties of mine
   ....
   ....
   ResumeLayout(false);
   PerformLayout();
}

I would like to know how to understand the designer or how to make it understand me???

Your help would be highly appreciated!

Thank you in advance!

King King
  • 61,710
  • 16
  • 105
  • 130
  • Perhaps this will help http://msdn.microsoft.com/en-us/library/system.componentmodel.defaultvalueattribute.aspx – Jras Apr 30 '13 at 03:10
  • No, DefaultAttribute is just to mark Bold or not Bold in the Properties window. However I've recognized that maybe I have to understand the designer, the problem is partly caused by myself. Initilize the properties in the constructor would work. – King King Apr 30 '13 at 04:47
  • Check out this link. I believe you need to mark the default values in your object so that the designer knows what the defaults should be. Try it out!! http://stackoverflow.com/questions/1980520/defaultvalue-attribute-is-not-working-with-my-auto-property – Jras Apr 30 '13 at 05:03

0 Answers0