Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Inherited default values

Inherited default values

Scheduled Pinned Locked Moved C#
csharpvisual-studiohelptutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chris_McGrath
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • C 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

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      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

      C 1 Reply Last reply
      0
      • M Martin 0

        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

        C Offline
        C Offline
        Chris_McGrath
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • C Chris_McGrath

          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

          M Offline
          M Offline
          Martin 0
          wrote on last edited by
          #4

          Hello 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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups