Microsoft Communities

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 draw a graphical representation of an enumeration using a UITypeEditor?

The following HatchStyleEditor class draws a graphical representation for values in the HatchStyle enumeration. HatchStyleEditor is derived from UITypeEditor and ovverides the GetPaintValueSupported method and returns true. GetPaintValueSupported indicates that this editor supports the painting of a representation of an object's value. PaintValue paints the representative value to the canvas.

public class HatchStyleEditor : UITypeEditor 
{ 
  public override bool GetPaintValueSupported( ITypeDescriptorContext context ) 
  { return true; }
 
  public override void PaintValue( PaintValueEventArgs e ) 
  { 
    if ( e.Value is HatchStyle ) 
    { 
      HatchStyle hatch = (HatchStyle) e.Value; 
      using ( Brush br = 
                new HatchBrush( hatch, SystemColors.WindowText,
                SystemColors.Window ) )
        e.Graphics.FillRectangle( br, e.Bounds ); 
    } 
  } 
}

Contributed from George Shepherd's Windows Forms FAQ



Page view counter