Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Design time support for protected property
 

Design time support for protected property

Maybe this is bad design, but...

I have a user control to give consistent buttons (save, refresh, cancel, etc) and behavior (state, styling, etc). I have a large number of protected get/set properties like 'ShowDeleteButton' and 'AllowDelete'. I made these properties protected because they should only be accessed by inheritted controls. To make my own life easier, I'd like these properties to show up in the designer for inheritted controls. If I make them public they show up. Is there a way to make them show up in the designer and/or is this a bad idea from a best practices standpoint?
JoshBlack  Thursday, August 13, 2009 4:13 PM
Hi,

Dear only the properties they made public will be showed in designer mode , because the control class has a relationship to the containment class. so that only the property they made public will be accessed at design time where you are placing .
All those property they are public will be availabe at deign time as they define in base control or child control all other access level impossible to view at design time.

Good luck
Malik M.Shahid  Friday, August 14, 2009 8:38 PM
The question ishow these properties should be treated?Only accessible from derived controls, butstill changable from the designer? I thinkyou have to choose one way. When I provide protected members to derived controls it is because the derived control should decidesomefunctionality provided by the base control. Normally I set these properties in thecontructor of the derived control.
If the usershould decidesomefeaturethrough the designer then the property should be made public beacuse then a derived control should have the option as well.

/Calle
- Still confused, but on a higher level -
Calle Mellergardh  Tuesday, August 18, 2009 5:32 PM
Hi,

Dear only the properties they made public will be showed in designer mode , because the control class has a relationship to the containment class. so that only the property they made public will be accessed at design time where you are placing .
All those property they are public will be availabe at deign time as they define in base control or child control all other access level impossible to view at design time.

Good luck
Malik M.Shahid  Friday, August 14, 2009 8:38 PM
The question ishow these properties should be treated?Only accessible from derived controls, butstill changable from the designer? I thinkyou have to choose one way. When I provide protected members to derived controls it is because the derived control should decidesomefunctionality provided by the base control. Normally I set these properties in thecontructor of the derived control.
If the usershould decidesomefeaturethrough the designer then the property should be made public beacuse then a derived control should have the option as well.

/Calle
- Still confused, but on a higher level -
Calle Mellergardh  Tuesday, August 18, 2009 5:32 PM

"Only accessible from derived controls, butstill changable from the designer? " - Yes

I chose protected because that would only be accessible to the inheritted control itself.

Example: an inherittedcontrol might display read-only data. I still want 'Find' and 'Refresh'. Whiledesigning the inherrited control, I can set 'ShowSaveButton' to false because this type of control should never support saving.

If I make that property public, code outside of the control could then turn that save button back on. The containing form, for example, could turn on the save button even though that makes no sense for a read-only version of the control. Granted the code in the containing form would also be my code, and I should know better. It just seems to be better design to hide properties from public that should only be accessed bythe control.

I just wanted to make them accessible in the designer without making it accesible everywhere. If I keep them protected, I guess there is no way to also have them show up in the designer?

Maybe there is a way to make a public property only accessible at design time and have a matching protected property that could be used by the inheritted control at run time?

JoshBlack  Thursday, August 20, 2009 5:18 PM

You can use google to search for other answers

Custom Search

More Threads

• Properties window keeps giving me "Object reference not set to an instance of an object." error
• Menus
• Details regarding UndoEngine Class in .NET
• ToolTip Font Change?
• Frames on top of each other
• System.ComponentModel.Design.ExceptionCollection thrown in user control subclass
• Really horrible experience
• Stylesheet in WinForm
• Error in designer when adding label to FlowLayout Panel
• prevent from resizing in desgin-time