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

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

Jan 01, 2016

Download

Documents

Charlene Ramsey
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Ray Konopka Developing Custom.NET Component Designers DevCon 2005 -- Course No: 4106.

Ray KonopkaRay Konopka

Developing Custom .NET Component Designers

Developing Custom .NET Component Designers

DevCon 2005 -- Course No: 4106DevCon 2005 -- Course No: 4106

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

2

AgendaAgenda

Component Techniques

Type Converters

UI Type Editors

Designers

Component Techniques

Type Converters

UI Type Editors

Designers

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

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.

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

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.

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

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

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

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.

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

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

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

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

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

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

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

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;

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

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

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

13

ExampleExample

RkClockHourHand, MinuteHand, SecondHand

properties

No Converter

Basic Text Converter

ExpandableObjectConverter

RkClockHourHand, MinuteHand, SecondHand

properties

No Converter

Basic Text Converter

ExpandableObjectConverter

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

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

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

15

ExampleExample

Enhanced HandTypeConverter.ConvertTo methodEnhanced HandTypeConverter.ConvertTo method

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

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

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

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

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

18

ExampleExample

RkLabel with StringEditorRkLabel with StringEditor

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

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

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

20

Custom DesignersCustom Designers

Descend from appropriate base class

Override Various methodsOnPaintAdornmentsPreFilterPropertiesDesignerVerbs

Descend from appropriate base class

Override Various methodsOnPaintAdornmentsPreFilterPropertiesDesignerVerbs

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

21

ExampleExample

RkClockDesignerOnPaintAdornmentsDesign-Time Only Property

RkClockDesignerOnPaintAdornmentsDesign-Time Only Property

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

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