This is a preview version of Cyotek's blog and may be missing functionality and/or unstable. Please visit https://www.cyotek.com/blog for the current version of the blog.
If you encounter any problems using this preview site, please contact us with the details.

Posts tagged with 'ComponentModel'

Creating a custom type converter part 3: Types to string

c# TypeConverter ComponentModel struct 2 Comments Downloads

I have discussed creating type converters a few times on this blog, and recently came across another use for them. I have a .NET Standard library that uses a variety of struct instances that are sometimes properties of concrete classes. I also have a .NET Framework 4.7.2 demonstration application to work with the library that uses the PropertyGrid control to provide easy editing facilities.

Note: While in this article I'm talking about using type converters purely in relation for use with the PropertyGrid control, this isn't their only purpose (just as well otherwise they wouldn't be a part of .NET Standard I assume). You can learn more about the TypeConverter class on MSDN.

Read More

Using alternate descriptions for enumeration members

c# reflection ComponentModel enum 1 Comments Downloads

The last two articles (here and here) described creating a custom type converter for converting units of measurement.

However, what happens when you want to display or convert to/from alternative representations? For example, consider the enum below.

Read More

Creating a custom TypeConverter part 2 - Instance descriptors, expandable properties and standard values

c# TypeConverter ComponentModel InstanceDescriptor 4 Comments Downloads

In the first part of this article series, I described how to create a simple type converter for converting an object to and from a string. This follow up article expands upon that sample, to include more concise design time code generation, expandable property support and finally custom lists of values.

The examples in this article assume you are working from the original sample project from part 1.

Read More

Creating a custom TypeConverter part 1 - getting started

c# TypeConverter ComponentModel 1 Comments Downloads

It is common practice to create a class that describes something, a person, a product - some entity or other. Your application may provide a sublime UI for editing these objects, or rely on something more basic such as a PropertyGrid. However, if you use this approach, you may find that some of your properties can't be edited. Yet examples abound of non-simple editing via the grid, such as colours, enumerations and image selection to name a few.

By making use of the TypeConverter and UITypeEditor classes, you can quite easily provide the ability to create richer editing support for your objects. This first article in this series will detail how to use TypeConverter allowing complex objects to be edited as though they were simple strings.

Read More