Inherited default values
-
Ok, I'm having a few problems with designer in Visual Studio... I have a MainToolbar class which has buttons on it (e.g. Forward, Back). The buttons are private but they're exposed publicly via various Properties, e.g. ForwardShown, ForwardEnabled. These properties have 3 Attributes... [Browsable(true), Category("Icons Visible"), DefaultValue(true)] Now I place the MainToolbar on a Form called FormBaseEdit and it works well. The value for the properties like ForwardShown is true and NOT bold (as it should be). The MainToolbar is a protected member of FormBaseEdit. The problem comes when I then inherit from FormBaseEdit. The properties of the MainToolbar is still true However they are now BOLD. IF you change them to false they are not bold. Then when you build the project the properties that you changed to false are automatically back to true. Does anyone know how to stop this? Thanks, Chris McGrath
-
Ok, I'm having a few problems with designer in Visual Studio... I have a MainToolbar class which has buttons on it (e.g. Forward, Back). The buttons are private but they're exposed publicly via various Properties, e.g. ForwardShown, ForwardEnabled. These properties have 3 Attributes... [Browsable(true), Category("Icons Visible"), DefaultValue(true)] Now I place the MainToolbar on a Form called FormBaseEdit and it works well. The value for the properties like ForwardShown is true and NOT bold (as it should be). The MainToolbar is a protected member of FormBaseEdit. The problem comes when I then inherit from FormBaseEdit. The properties of the MainToolbar is still true However they are now BOLD. IF you change them to false they are not bold. Then when you build the project the properties that you changed to false are automatically back to true. Does anyone know how to stop this? Thanks, Chris McGrath
Hello Chris, it seems that you forgot to initialize the local variables of your properties. Setting the DefaultValue Attribute to "true" is not sufficient. If it was DefaultValue(false), you would have luck because the boolean default is "false". That means you would have to do:
private bool testProp = true; \[Browsable(true), Category("Icons Visible"), DefaultValue(true)\] public bool TestProp { get { return testProp; } set { testProp=value; } }
All the best, Martin
-
Hello Chris, it seems that you forgot to initialize the local variables of your properties. Setting the DefaultValue Attribute to "true" is not sufficient. If it was DefaultValue(false), you would have luck because the boolean default is "false". That means you would have to do:
private bool testProp = true; \[Browsable(true), Category("Icons Visible"), DefaultValue(true)\] public bool TestProp { get { return testProp; } set { testProp=value; } }
All the best, Martin
My MainToolbar contains a ToolStrip which has the buttons on it, the buttons already default to true, so my properties look like
[Browsable(true), Category("Icons Visible"), DefaultValue(true)] public virtual bool FirstShown { get { return btnFirst.Visible; } set { btnFirst.Visible = value; } }
As I said it works perfectly if I place it on a form. The problem is when I inherit from the form which it is on, the Default Value Actually changes from false to true. So if I change FirstShown to false, it looses its boldness, doesn't write the line in the designer file, and when it builds it puts the value back to true. Thanks, Chris -
My MainToolbar contains a ToolStrip which has the buttons on it, the buttons already default to true, so my properties look like
[Browsable(true), Category("Icons Visible"), DefaultValue(true)] public virtual bool FirstShown { get { return btnFirst.Visible; } set { btnFirst.Visible = value; } }
As I said it works perfectly if I place it on a form. The problem is when I inherit from the form which it is on, the Default Value Actually changes from false to true. So if I change FirstShown to false, it looses its boldness, doesn't write the line in the designer file, and when it builds it puts the value back to true. Thanks, ChrisHello Chris, Hmmm? I tested it now with a simple user control which has a button on it. I placed it on a baseform and inherit a formclass from that baseform. And.. Same effect than you have!! I have no real explination for that, but it hs something todo with the timing of the designer. The designer runns the constructor code of your controls, maybe at the time where he whants to get youre property, the button is not initialized. (Just out of my head.) I would suggest you aworkaround like this:
private bool testProp = true; \[Browsable(true), Category("Icons Visible"), DefaultValue(true)\] public bool TestProp { get { return testProp;//button1.Visible; } set { testProp = value; button1.Visible=value; } }
Hope it helps! All the best, Martin