/// <summary> /// Draw a preview of the <see cref="XPanelColorPair" /> /// </summary> /// <param name="e">The paint event args providing the <see cref="Graphics" /> and bounding /// rectangle</param> public override void PaintValue(PaintValueEventArgs e) { XPanelColorPair colorPair = (XPanelColorPair)e.Value; using (SolidBrush b = new SolidBrush(colorPair.Background)) { e.Graphics.FillRectangle(b, e.Bounds); } // Draw the text "ab" using the Foreground/Background values from the ColorPair using (SolidBrush b = new SolidBrush(colorPair.Foreground)) { using (Font f = new Font("Arial", 6)) { RectangleF temp = new RectangleF(e.Bounds.Left, e.Bounds.Top, e.Bounds.Height, e.Bounds.Width); temp.Inflate(-2, -2); // Set up how we want the text drawn StringFormat format = new StringFormat(StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap); format.Trimming = StringTrimming.EllipsisCharacter; format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; // save the Smoothing mode of the Graphics object so we can restore it SmoothingMode saveMode = e.Graphics.SmoothingMode; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.DrawString("ab", f, b, temp, format); e.Graphics.SmoothingMode = saveMode; } } }
/// <summary> /// Construct a <see cref="XPanelColorPair" /> from the properties in a <see cref="IDictionary" /> /// </summary> /// <param name="context">designer context</param> /// <param name="propertyValues">The "serialized" values for the <see cref="XPanelColorPair" /></param> /// <returns>A <see cref="XPanelColorPair" /></returns> public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues) { XPanelColorPair colorPair = new XPanelColorPair(); colorPair.Foreground = (System.Drawing.Color)propertyValues["Foreground"]; colorPair.Background = (System.Drawing.Color)propertyValues["Background"]; return((object)colorPair); }