Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I make properties of custom data types browsable in the Property browser?

If you have a custom data type like this:

public class CustomSize 
{ 
  public int Width { get { /*...*/ } set { /*...*/ } } 
  public int Height { get { /*...*/ } set { /*...*/ } } 
} 

Then write this:

public class CustomSizeConverter : ExpandableObjectConverter 
{ 
  public override bool GetCreateInstanceSupported( ITypeDescriptorContext context ) 
  { return true; }

  public override object CreateInstance( ITypeDescriptorContext context,
    IDictionary propertyValues ) 
  { 
    CustomSize size = new CustomSize(); 
    size.Width = (int) propertyValues[ (object) "Width" ]; 
    size.Height = (int) propertyValues[ (object) "Height" ]; 
    return size; 
  } 
}

Contributed from George Shepherd's Windows Forms FAQ



Page view counter