by Amr Elsehemy
17. January 2008 05:52
In the previous posts in this series I introduced how to use some basic and advanced Attributes and how to add an image for your control to appear in the toolbox and then I gave an introduction on TypeConverters and examples here and here on how to use the TypeConverters. Now I will give an introduction on how UITypeEditors used in design time.
First, what is a UITypeEditor anyway from MSDN :
The UITypeEditor class provides a base class that you can derive from and extend to implement a custom type editor for the design-time environment. Typically, your custom type editor interacts with the PropertyGrid control.
More...
by Amr Elsehemy
14. January 2008 10:16
The last post in the series I have showed you how to implement a custom TypeConverter and override some of the virtual methods from the base class.
In this post I'll show how to some more advanced examples on how to get the most of TypeConverters. First look at the strucure of the example.
More...
by Amr Elsehemy
12. January 2008 23:33
In the previous post I gave an introduction on common TypeConverters and how to use them, in this post I will show you how to implement custom TypeConverters for your own custom data types.
First, lets explore the TypeConverter base type virtual methods ...
| Method | Description |
| CanConvertFrom |
Returns a Boolean value indicating whether the converter can convert an object of the specified type to the type that this converter represents. |
| CanConvertTo |
Returns a Boolean value indicating whether the converter can convert an object to the specified type. |
| ConvertFrom |
Converts the specified value to the type represented by this converter. |
| ConvertFromInvariantString |
Converts the string representation of a value to a type that this converter represents, using the invariant culture, which is English. |
| ConvertFromString |
Converts the string representation of a value to a type that this converter represents, using the given culture. |
| ConvertTo |
Converts the given object to the specified type. |
| ConvertToInvariantString |
Converts the given object to a string, using the invariant culture. |
| ConvertToString |
Converts the given object to a string, using the specified culture. |
| CreateInstance |
Creates or recreates an object given a dictionary of property values. The dictionary contains property name-value pairs. |
| GetCreateInstanceSupported |
Returns a Boolean value indicating whether CreateInstance has been implemented. |
| GetProperties |
Returns a collection of PropertyDescriptor objects for the given object. |
| GetPropertiesSupported |
Returns a Boolean value indicating whether the given object supports properties. |
| GetStandardValues |
Returns a collection of standard values for the type that this converter represents. |
| GetStandardValuesExclusive |
Returns a Boolean value indicating whether the standard values are mutually exclusive. |
| GetStandardValuesSupported |
Returns a Boolean value indicating whether GetStandardValues is implemented. |
| IsValid |
Returns a Boolean value indicating whether the specified value is valid for the type that this converter represents. |
More...
by Amr Elsehemy
12. January 2008 11:57
I mentioned in my Introduction post of this series the TypeConverters
Overview: For those who don't know what is a TypeConverter you can expect that it is something responsible to convert between types, there are times when you need to convert from one data type to another. Type converters are classes that describe how a particular object converts to and from other data types. For example, to display a date on the screen(console, windows form, web ..) it will need to be converted to a string representation. Vice Versa is true, if there is a string value of a date that needs to be stored for example in database. Usually casting is enough when the types are simple. But with complex types, a better technique is used.
TypeConverters are classes that define how an object converts to and from other types. Which are used during design time for sting conversion ( used by the PropertyGrid ), also in runtime in validations and conversions.
So, first lets take a look on some of the Common .NET Type Converters that are already built for us to use.
All the following classes are in the System.ComponentModel and the System.Drawing namespaces.
- StringConverter
- BooleanConverter
- CharConverter
- CollectionConverter
- CultureInfoConverter
- DateTimeConverter
- EnumConverter
- ExpandableObjectConverter
- GuidConverter
- TimeSpanConverter
- ColorConverter
- FontConverter
- PointConverter
- RectangleConverter
- SizeConverter
And much more. More...
by Amr Elsehemy
8. January 2008 02:15
| Attributes | Applied To | Description |
| ToolboxBitmap |
Controls |
Allows you to specify an icon to represent a control in a container, such as the Microsoft Visual Studio Form Designer. |
» ToolboxBitmapAttribute if you want to redistribute your custom control you should use this attribute to add an icon to it.
[ToolboxBitmap(typeof(Button))]
public class ButtonEx : Button
This will show the default icon of the Windows.Forms.Button control, to add a custom icon you will use one of the other two ToolboxBitmapAttribute constructors, the first one accepts a string as the full path for the image, the second one with a string and a type this one is used more frequently.
[ToolboxBitmap(typeof(ButtonEx),"ButtonEx.png")]
public class ButtonEx : Button
Note: For this to work you need to be sure of 2 things:
- The image name would be exactly spelled as the type (control).
- Right click the image and make sure its BuildAction is Embedded Resource.
by Amr Elsehemy
7. January 2008 11:39
In my previous post I pointed out the most common used Attributes for Design Time Support. In this part I will point out some more Attributes that take advantage of the Design Time Environment.
| Attributes | Applied To | Description |
| DisplayName |
Properties & Events |
Specifies the display name for a property or an event. |
| ParenthesizeProperty |
Properties |
Indicates whether the name of the associated property is displayed with parentheses in the Properties window. |
| RefreshProperties |
Properties |
Indicates that the property grid should refresh when the associated property value changes. |
| NotifyParentProperty |
Properties |
Indicates that the parent property is notified when the value of the property that this attribute is applied to is modified. |
| ReadOnly |
Properties |
Specifies whether the property this attribute is bound to is read-only or read/write. |
| DesignOnly |
Properties |
Specifies whether a property can only be set at design time.
|
More...
by Amr Elsehemy
6. January 2008 10:56
As I mentioned in my previous post, I am willing to write a multi part tutorial on how to add Design Time Support to your custom controls.
In this part, I will talk about the common attributes for Properties and Events
| Attribute | Applied To | Description |
| Browsable |
Properties and events |
Specifies whether a property or an event should be displayed in the property browser. |
| Category |
Properties and events
|
Specifies the name of the category in which to group a property or event. When categories are used, component properties and events can be displayed in logical groupings in the property browser. |
| Description |
Properties and events |
Defines a small block of text to be displayed at the bottom of the property browser when the user selects a property or event. |
| DefaultProperty |
Properties
(Insert this attribute before the class declaration.) |
Specifies the default property for the component. This property is selected in the property browser when a user clicks on the control. |
| DefaultValue |
Properties |
Sets a simple default value for a property. |
| DefaultEvent |
Events
(Insert this attribute before the class declaration.) |
Specifies the default event for the component. This is the event that is selected in the property browser when a user clicks on the component. |
To illustrate how these attributes work I need first to set a custom control, let's start with simple windows forms button. More...
by Amr Elsehemy
4. January 2008 13:40
In my amr-elsehemy.blogspot.com I started a design time support tutorial for custom controls but I didn't manage to finish them so I will start my blog here on amrelsehemy.net by editing my previous posts and adding new tutorials.
So if you came from my blogspot you may still find some new useful information, so lets start.
You need to be familiar with some terms when working with the design time environment .
More...