c# - Persisting Design Time Properties in WinForms -
i writing stylable control windows forms. stylable mean user has greater control on appearance of control
standard backcolor
, forecolor
etc. following code has been simplified illustrate problem
[toolboxitem(false)] public class brushproperties : component { public color[] gradientcolors { get; set; } public single[] gradientpositions { get; set; } public single gradientangle { get; set; } } [toolboxitem(false)] public class style : component { public brushproperties background { get; set; } public brushproperties foreground { get; set; } public style() { this.background = new brushproperties(); this.foreground = new brushproperties(); } } public class stylecontrol : control { public style style { get; set; } public stylecontrol() { this.style = new style(); } }
when in designer can see of properties of style
, of properties of each brushproperties
instance. can change values well, moment build/run project, values i've assigned properties disappear. code require in order persist property values specified @ design time?
if goal have design-time support, don't need base classes component
object. instead decorate classes expandableobjectconverter
attribute.
the propertygrid
use expandableobjectconverter
attribute determine whether if should expand properties of object or not.
example:
[toolboxitem(false)] [typeconverter(typeof(expandableobjectconverter))] public class brushproperties { public color[] gradientcolors { get; set; } public single[] gradientpositions { get; set; } public single gradientangle { get; set; } } [toolboxitem(false)] [typeconverter(typeof(expandableobjectconverter))] public class style { public brushproperties background { get; set; } public brushproperties foreground { get; set; } public style() { this.background = new brushproperties(); this.foreground = new brushproperties(); } }
Comments
Post a Comment