Ray Konopka Developing Custom .NET Component Designers DevCon 2005 -- Course No: 4106
Jan 01, 2016
Ray KonopkaRay Konopka
Developing Custom .NET Component Designers
Developing Custom .NET Component Designers
DevCon 2005 -- Course No: 4106DevCon 2005 -- Course No: 4106
2
AgendaAgenda
Component Techniques
Type Converters
UI Type Editors
Designers
Component Techniques
Type Converters
UI Type Editors
Designers
3
DesignModeDesignMode
DesignMode is true if the component is currently be used at design-time
NOTEDesignMode should not be checked from
within the constructor or any code called from the constructor.
Constructor called before component assigned to a site.
Site determines whether component is in design mode or not.
DesignMode is true if the component is currently be used at design-time
NOTEDesignMode should not be checked from
within the constructor or any code called from the constructor.
Constructor called before component assigned to a site.
Site determines whether component is in design mode or not.
5
Component Related Attributes
Component Related Attributes
CategorySpecify category property will be grouped in
Object Inspector
DescriptionSpecify a short description displayed when
associated property is selected in Object Inspector
BrowsableDetermines whether the associated property is
visible in Object Inspectorpublic vs. published.
CategorySpecify category property will be grouped in
Object Inspector
DescriptionSpecify a short description displayed when
associated property is selected in Object Inspector
BrowsableDetermines whether the associated property is
visible in Object Inspectorpublic vs. published.
6
Component Related Attributes
Component Related Attributes
ReadOnlyDetermines if associated property can be edited
in Object Inspector.
DefaultValueSpecify a value to be considered “default” for
the property
LocalizableProperty value can be localized without
modifying the source code
ReadOnlyDetermines if associated property can be edited
in Object Inspector.
DefaultValueSpecify a value to be considered “default” for
the property
LocalizableProperty value can be localized without
modifying the source code
7
Component Related Attributes
Component Related Attributes
MergablePropertyDetermines if associated property is visible
when multiple components are selected
RefreshPropertiesAssociate with a property that changes other
property values
DefaultEventSpecify event the form designer will hook up
when the control is double-clicked.
MergablePropertyDetermines if associated property is visible
when multiple components are selected
RefreshPropertiesAssociate with a property that changes other
property values
DefaultEventSpecify event the form designer will hook up
when the control is double-clicked.
8
Component Related Attributes
Component Related Attributes
ToolboxBitmapAssociate an image with the component for
display in a toolbox16x16 pixel 16-color image or icon added to
assembly as a resource
ToolboxBitmapAssociate an image with the component for
display in a toolbox16x16 pixel 16-color image or icon added to
assembly as a resource
9
Component Palette ImagesComponent Palette Images
Typically avoid using ToolboxBitmap
Instead, just add bitmap or icon file to your assembly project
(In Delphi) Filename must match name of component class and include the namespaceRaize.Samples.WinForms.Delphi.RkSpinner.bmp
Typically avoid using ToolboxBitmap
Instead, just add bitmap or icon file to your assembly project
(In Delphi) Filename must match name of component class and include the namespaceRaize.Samples.WinForms.Delphi.RkSpinner.bmp
10
Type ConvertersType Converters
System.ComponentModel.TypeConverter
Performs similar role to VCL Property Editors
Convert one type to another and backInteger <-> StringEnum <-> String
Property Inspector uses a type converter for each property displayed
Can be used outside of design environment
ExamplesStringConverter, Int32Converter,
DateTimeConverter
System.ComponentModel.TypeConverter
Performs similar role to VCL Property Editors
Convert one type to another and backInteger <-> StringEnum <-> String
Property Inspector uses a type converter for each property displayed
Can be used outside of design environment
ExamplesStringConverter, Int32Converter,
DateTimeConverter
11
Custom TypeConvertersCustom TypeConverters
TypeConverters can also handle complex propertiese.g. sub-properties
TypeConverters can also handle complex propertiese.g. sub-propertiesHand = class
private FLineColor: Color; FWidth: Integer;public constructor Create( aLineColor: Color; aWidth: Integer );published property LineColor: Color read FLineColor write FLineColor; property Width: Integer read FWidth write FWidth;end;
Hand = classprivate FLineColor: Color; FWidth: Integer;public constructor Create( aLineColor: Color; aWidth: Integer );published property LineColor: Color read FLineColor write FLineColor; property Width: Integer read FWidth write FWidth;end;
12
Create Custom TypeConverterCreate Custom TypeConverter
Descend from TypeConverter or descendant
Override appropriate methodsCanConvertFromConvertFromConvertTo
Associate converter with property using TypeConverter attribute
Descend from TypeConverter or descendant
Override appropriate methodsCanConvertFromConvertFromConvertTo
Associate converter with property using TypeConverter attribute
13
ExampleExample
RkClockHourHand, MinuteHand, SecondHand
properties
No Converter
Basic Text Converter
ExpandableObjectConverter
RkClockHourHand, MinuteHand, SecondHand
properties
No Converter
Basic Text Converter
ExpandableObjectConverter
14
Serialization with TypeConverters
Serialization with TypeConverters
Hand properties are displayable in Property Inspector
But even if you make changes, they are not serialized
Need to do some extra stepsCreate a private ShouldSerialXxxx methodCreate a private ResetXxxx methodReturn an InstanceDescriptor in ConvertTo
method
Hand properties are displayable in Property Inspector
But even if you make changes, they are not serialized
Need to do some extra stepsCreate a private ShouldSerialXxxx methodCreate a private ResetXxxx methodReturn an InstanceDescriptor in ConvertTo
method
15
ExampleExample
Enhanced HandTypeConverter.ConvertTo methodEnhanced HandTypeConverter.ConvertTo method
16
UITypeEditorsUITypeEditors
Provides enhanced editing capabilities in Property Inspector
Also similar to VCL Property Editors
System.Drawing.Design.UITypeEditor
ExamplesFontEditorColorEditorImageEditor
Provides enhanced editing capabilities in Property Inspector
Also similar to VCL Property Editors
System.Drawing.Design.UITypeEditor
ExamplesFontEditorColorEditorImageEditor
17
Custom UITypeEditorsCustom UITypeEditors
Create a descendant class
Override GetEditStyle methodUITypeEditorEditStyle.DropDownUITypeEditorEditStyle.ModalUITypeEditorEditStyle.None
Override EditValue
Optionally override additional methodsGetPaintValueSupportedPaintValue
Associate with property with Editor attribute
Create a descendant class
Override GetEditStyle methodUITypeEditorEditStyle.DropDownUITypeEditorEditStyle.ModalUITypeEditorEditStyle.None
Override EditValue
Optionally override additional methodsGetPaintValueSupportedPaintValue
Associate with property with Editor attribute
18
ExampleExample
RkLabel with StringEditorRkLabel with StringEditor
19
DesignersDesigners
Similar in function to VCL Component Editors
System.ComponentModel.Design.ComponentDesignerSystem.Windows.Forms.Design.ControlDes
ignerSystem.Web.UI.Design.ControlDesigner
Handles Design-Time Display changes
Context Menu Items
Design-Time only properties
Similar in function to VCL Component Editors
System.ComponentModel.Design.ComponentDesignerSystem.Windows.Forms.Design.ControlDes
ignerSystem.Web.UI.Design.ControlDesigner
Handles Design-Time Display changes
Context Menu Items
Design-Time only properties
20
Custom DesignersCustom Designers
Descend from appropriate base class
Override Various methodsOnPaintAdornmentsPreFilterPropertiesDesignerVerbs
Descend from appropriate base class
Override Various methodsOnPaintAdornmentsPreFilterPropertiesDesignerVerbs
21
ExampleExample
RkClockDesignerOnPaintAdornmentsDesign-Time Only Property
RkClockDesignerOnPaintAdornmentsDesign-Time Only Property
22
The Finish LineThe Finish Line
Contact Information
Evaluation Forms
Questions & Answers
Contact Information
Evaluation Forms
Questions & Answers
Ray [email protected]://www.raize.com
Ray [email protected]://www.raize.com