using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace Drew.Gdi { public class HatchStylePanel : Control { private const int Padding = 12; private const int RectangleHeight = 19; private const int RectangleWidth = 110; private const int HorizontalSpacing = 24; private const int VerticalSpacing = 34; public HatchStylePanel() { SetStyle(ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw, true); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; Font fnt = new Font("Arial", 8); Rectangle rect = new Rectangle(Padding, Padding, RectangleWidth, RectangleHeight); foreach (string name in Enum.GetNames(typeof(HatchStyle))) { HatchStyle hs = (HatchStyle)Enum.Parse(typeof(HatchStyle), name); using (HatchBrush myBrush = new HatchBrush(hs, Color.Black, Color.White)) { g.FillRectangle(myBrush, rect); Rectangle rectThinLine = rect; Rectangle rectThickLine = rect; rectThinLine.Inflate(4, 4); rectThickLine.Inflate(8, 8); g.DrawRectangle(new Pen(myBrush, 1), rectThinLine); g.DrawRectangle(new Pen(myBrush, 2), rectThickLine); } g.DrawString(name, fnt, Brushes.Black, rect.Left - 8, rect.Bottom + 10); // move down rect.Y += rect.Height + VerticalSpacing; // if we're off the bottom, start the next column if (rect.Bottom > Height) { rect.X += rect.Width + HorizontalSpacing; rect.Y = Padding; } } fnt.Dispose(); } } }