views:

144

answers:

1

I have a user control panel that has two buttons on it. Other user controls inherit from this control and set a property to true if the buttons should be visible. Everything runs how I want it to but what I'm looking for is a way to clear these buttons from the designer window for forms where this property is left at false.

looks like:

[DefaultValue(false)]
public bool ShowButtons{
  set
  { 
    mShowButtons = value;
    UpdateButtons();
  }
  get
  {
    return mShowButtons;
  }
}

This property shows in the properties window and the buttons are always shown in the designer window. Is there some way to have the designer evaluate this when the property is changed to get the buttons to clear from the inheriting form? I was unable find a designer attribute to do this.

A: 

Try adding a get:

bool mShowButtons;
[DefaultValue(false)]
public bool ShowButtons
{
  get
  {
     return mShowButtons;
  }
  set
  { 
    mShowButtons = value;
    UpdateButtons();
  }
}

Now when editing your derived class in the Designer, you should be able to see a ShowButtons property in properties window when the derived UserControl is selected. (It will be in the "Misc" section unless you add the appropriate attribute). If you set it there, it should have the appropriate affect in the Designer (Assuming the contents of the UpdateButtons() function work correctly)).

A property must be public and have bot get and set in order to display in the Properties editor window. Once it is, then setting the value in the properties window will "save" that setting for the designed control in the control's resources/implementation.

I use this functionality quite often to specialize derived UserControls, so I know it should work for you (although there may be other issues at play).

ee
sorry, I left the get out for brevity. The property does show in the properties window and is saved correctly and UpdateButtons functions correctly. As far as I can tell this is just a designer issue.
jan