Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ray Konopka Developing Custom.NET Component Designers DevCon 2005 -- Course No: 4106.

Similar presentations


Presentation on theme: "Ray Konopka Developing Custom.NET Component Designers DevCon 2005 -- Course No: 4106."— Presentation transcript:

1 Ray Konopka Developing Custom.NET Component Designers DevCon 2005 -- Course No: 4106

2 2 Agenda Component Techniques Type Converters UI Type Editors Designers Component Techniques Type Converters UI Type Editors Designers

3 3 DesignMode DesignMode is true if the component is currently be used at design-time NOTE DesignMode 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 NOTE DesignMode 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.

4 4 Attributes Attributes used to modify the behavior of properties, methods, events, classes, etc. [ Category( 'Appearance' ) ] [ Description( 'The width of buttons, in pixels.' ) ] [ DefaultValue( 18 ) ] property ButtonWidth: Integer read... write...; [ Category( 'Appearance' ) ] [ Description( 'The width of buttons, in pixels.' ) ] [ DefaultValue( 18 ) ] property ButtonWidth: Integer read... write...;

5 5 Component Related Attributes Category Specify category property will be grouped in Object Inspector Description Specify a short description displayed when associated property is selected in Object Inspector Browsable Determines whether the associated property is visible in Object Inspector public vs. published. Category Specify category property will be grouped in Object Inspector Description Specify a short description displayed when associated property is selected in Object Inspector Browsable Determines whether the associated property is visible in Object Inspector public vs. published.

6 6 Component Related Attributes ReadOnly Determines if associated property can be edited in Object Inspector. DefaultValue Specify a value to be considered “default” for the property Localizable Property value can be localized without modifying the source code ReadOnly Determines if associated property can be edited in Object Inspector. DefaultValue Specify a value to be considered “default” for the property Localizable Property value can be localized without modifying the source code

7 7 Component Related Attributes MergableProperty Determines if associated property is visible when multiple components are selected RefreshProperties Associate with a property that changes other property values DefaultEvent Specify event the form designer will hook up when the control is double-clicked. MergableProperty Determines if associated property is visible when multiple components are selected RefreshProperties Associate with a property that changes other property values DefaultEvent Specify event the form designer will hook up when the control is double-clicked.

8 8 Component Related Attributes ToolboxBitmap Associate an image with the component for display in a toolbox 16x16 pixel 16-color image or icon added to assembly as a resource ToolboxBitmap Associate an image with the component for display in a toolbox 16x16 pixel 16-color image or icon added to assembly as a resource

9 9 Component 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 namespace Raize.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 namespace Raize.Samples.WinForms.Delphi.RkSpinner.bmp

10 10 Type Converters System.ComponentModel.TypeConverter Performs similar role to VCL Property Editors Convert one type to another and back Integer String Enum String Property Inspector uses a type converter for each property displayed Can be used outside of design environment Examples StringConverter, Int32Converter, DateTimeConverter System.ComponentModel.TypeConverter Performs similar role to VCL Property Editors Convert one type to another and back Integer String Enum String Property Inspector uses a type converter for each property displayed Can be used outside of design environment Examples StringConverter, Int32Converter, DateTimeConverter

11 11 Custom TypeConverters TypeConverters can also handle complex properties e.g. sub-properties TypeConverters can also handle complex properties e.g. sub-properties Hand = 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 = 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;

12 12 Create Custom TypeConverter Descend from TypeConverter or descendant Override appropriate methods CanConvertFrom ConvertFrom ConvertTo Associate converter with property using TypeConverter attribute Descend from TypeConverter or descendant Override appropriate methods CanConvertFrom ConvertFrom ConvertTo Associate converter with property using TypeConverter attribute

13 13 Example RkClock HourHand, MinuteHand, SecondHand properties No Converter Basic Text Converter ExpandableObjectConverter RkClock HourHand, MinuteHand, SecondHand properties No Converter Basic Text Converter ExpandableObjectConverter

14 14 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 steps Create a private ShouldSerialXxxx method Create a private ResetXxxx method Return 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 steps Create a private ShouldSerialXxxx method Create a private ResetXxxx method Return an InstanceDescriptor in ConvertTo method

15 15 Example Enhanced HandTypeConverter.ConvertTo method

16 16 UITypeEditors Provides enhanced editing capabilities in Property Inspector Also similar to VCL Property Editors System.Drawing.Design.UITypeEditor Examples FontEditor ColorEditor ImageEditor Provides enhanced editing capabilities in Property Inspector Also similar to VCL Property Editors System.Drawing.Design.UITypeEditor Examples FontEditor ColorEditor ImageEditor

17 17 Custom UITypeEditors Create a descendant class Override GetEditStyle method UITypeEditorEditStyle.DropDown UITypeEditorEditStyle.Modal UITypeEditorEditStyle.None Override EditValue Optionally override additional methods GetPaintValueSupported PaintValue Associate with property with Editor attribute Create a descendant class Override GetEditStyle method UITypeEditorEditStyle.DropDown UITypeEditorEditStyle.Modal UITypeEditorEditStyle.None Override EditValue Optionally override additional methods GetPaintValueSupported PaintValue Associate with property with Editor attribute

18 18 Example RkLabel with StringEditor

19 19 Designers Similar in function to VCL Component Editors System.ComponentModel.Design.ComponentDesigner System.Windows.Forms.Design.ControlDesigner System.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.ComponentDesigner System.Windows.Forms.Design.ControlDesigner System.Web.UI.Design.ControlDesigner Handles Design-Time Display changes Context Menu Items Design-Time only properties

20 20 Custom Designers Descend from appropriate base class Override Various methods OnPaintAdornments PreFilterProperties DesignerVerbs Descend from appropriate base class Override Various methods OnPaintAdornments PreFilterProperties DesignerVerbs

21 21 Example RkClockDesigner OnPaintAdornments Design-Time Only Property RkClockDesigner OnPaintAdornments Design-Time Only Property

22 22 The Finish Line Contact Information Evaluation Forms Questions & Answers Contact Information Evaluation Forms Questions & Answers Ray Konopka rkonopka@raize.com http://www.raize.com Ray Konopka rkonopka@raize.com http://www.raize.com


Download ppt "Ray Konopka Developing Custom.NET Component Designers DevCon 2005 -- Course No: 4106."

Similar presentations


Ads by Google