Welcome to WindowsClient.net | Sign in | Join

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

Windows Forms FAQs

How to make properties in your custom data type appear in a particular order in the property browser?

For example, if you have a custom type:

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

And you want to the Width and Height properties to appear in that order, then provide this override:

public override bool GetPropertiesSupported( ITypeDescriptorContext context ) 
{ return true; }

public override PropertyDescriptorCollection GetProperties( 
  ITypeDescriptorContext context, object value, Attribute[] attributes ) 
{ 
  string[] propNames = new string[] { "Width", "Height" }; 
  PropertyDescriptorCollection pdc = 
    TypeDescriptor.GetProperties( typeof( System.Drawing.Size ), attributes ); 
  return pdc.Sort( propNames ); 
}

Contributed from George Shepherd's Windows Forms FAQ



Page view counter