Live Chat Icon For mobile
Live Chat Icon

How can I paint a representation of enum values using a UITypeEditor?

Platform: WinForms| Category: Type Editors

The following HatchStyleEditor class draws a graphical representation for values in the HatchStyle enumeration. HatchStyleEditor is derived from UITypeEditor and overrides 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;
            Brush br = new HatchBrush(hatch, SystemColors.WindowText, SystemColors.Window);
            e.Graphics.FillRectangle(br, e.Bounds);
            br.Dispose();
        }
    }
}

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.