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. Windows Forms
  4. UserControl properties don't match in designer and InitializeComponent

UserControl properties don't match in designer and InitializeComponent

Scheduled Pinned Locked Moved Windows Forms
csharpvisual-studiohelpalgorithmsregex
2 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.
  • D Offline
    D Offline
    dybs
    wrote on last edited by
    #1

    So here's a wierd one.... (sorry for the length, but this needs some 'splainin) I have a UserControl consisting of a TextBox, a Label, and a CheckBox. I have a ShowCheckBox property like so:

    [Browsable(true),
    DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
    EditorBrowsable(EditorBrowsableState.Always),
    Bindable(true),
    Category("Behavior"),
    DefaultValue(true)]
    public bool ShowCheckBox
    {
    get
    {
    return checkbox.Visible;
    }
    set
    {
    checkBox.Visible = value;
    }
    }

    (If you see any compile errors, ignore them, I'm typing this from memory. The code I actually have does compile). This UserControl is part of the same project as my application. I can place several instances of these controls on my form and the ShowCheckBox property defaults to true, as it should. So far, so good. Now the weird part...through a variety of actions (switching tabs on the form, recompiling or running the application, etc.), suddenly my ShowCheckBox properties all get set to false, so I don't see the CheckBox in any of my UserControls in the form's designer! Sure enough, the values are all set to false in InitializeComponent. I then go back and reset the properties to true in the designer, and I see the property settings disappear from InitializeComponent (i.e. the default value is being used). After a little while, it happens again - the values magically get set to false again. I'm thinking this has something to do with the DesignerSerializationVisibility attribute? Even weirder...usually when something changes in InitializeComponent or in the designer, the change is automatically reflected in the other location. But when I see the property values set to false in InitializeComponent, I still see the property set to true in the designer! I probably spent about an hour or so searching Google and CP, and the only help I really found was in setting the attributes I have above. Is this a bug in Visual Studio by any chance? Or is there some other attribute I'm missing? I'm using VS 2005 SP1, C#, Windows XP SP3, all the latest updates. Thanks, Dybs

    M 1 Reply Last reply
    0
    • D dybs

      So here's a wierd one.... (sorry for the length, but this needs some 'splainin) I have a UserControl consisting of a TextBox, a Label, and a CheckBox. I have a ShowCheckBox property like so:

      [Browsable(true),
      DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
      EditorBrowsable(EditorBrowsableState.Always),
      Bindable(true),
      Category("Behavior"),
      DefaultValue(true)]
      public bool ShowCheckBox
      {
      get
      {
      return checkbox.Visible;
      }
      set
      {
      checkBox.Visible = value;
      }
      }

      (If you see any compile errors, ignore them, I'm typing this from memory. The code I actually have does compile). This UserControl is part of the same project as my application. I can place several instances of these controls on my form and the ShowCheckBox property defaults to true, as it should. So far, so good. Now the weird part...through a variety of actions (switching tabs on the form, recompiling or running the application, etc.), suddenly my ShowCheckBox properties all get set to false, so I don't see the CheckBox in any of my UserControls in the form's designer! Sure enough, the values are all set to false in InitializeComponent. I then go back and reset the properties to true in the designer, and I see the property settings disappear from InitializeComponent (i.e. the default value is being used). After a little while, it happens again - the values magically get set to false again. I'm thinking this has something to do with the DesignerSerializationVisibility attribute? Even weirder...usually when something changes in InitializeComponent or in the designer, the change is automatically reflected in the other location. But when I see the property values set to false in InitializeComponent, I still see the property set to true in the designer! I probably spent about an hour or so searching Google and CP, and the only help I really found was in setting the attributes I have above. Is this a bug in Visual Studio by any chance? Or is there some other attribute I'm missing? I'm using VS 2005 SP1, C#, Windows XP SP3, all the latest updates. Thanks, Dybs

      M Offline
      M Offline
      mp31415
      wrote on last edited by
      #2

      This thread seems to be related: http://www.eggheadcafe.com/software/aspnet/32319410/defaultvalue-attribute-on.aspx

      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