using System.Drawing; namespace System.Windows.Forms { public class DrawItemEventArgs : EventArgs { private Color backColor; private Color foreColor; private Font font; private readonly Graphics graphics; private readonly int index; private readonly Rectangle rect; private readonly DrawItemState state; public Color BackColor { get { if ((state & DrawItemState.Selected) == DrawItemState.Selected) { return System.Drawing.SystemColors.Highlight; } if ((state & DrawItemState.Disabled) == DrawItemState.Disabled) { return System.Drawing.SystemColors.Control; } if ((state & DrawItemState.HotLight) == DrawItemState.HotLight) { return System.Drawing.SystemColors.ControlLight; } return backColor; } } public Rectangle Bounds => rect; public Font Font => font; public Color ForeColor { get { if ((state & DrawItemState.Selected) == DrawItemState.Selected) { return System.Drawing.SystemColors.HighlightText; } if ((state & DrawItemState.Disabled) == DrawItemState.Disabled) { return System.Drawing.SystemColors.GrayText; } return foreColor; } } public Graphics Graphics => graphics; public int Index => index; public DrawItemState State => state; public DrawItemEventArgs(Graphics graphics, Font font, Rectangle rect, int index, DrawItemState state) { this.graphics = graphics; this.font = font; this.rect = rect; this.index = index; this.state = state; foreColor = System.Drawing.SystemColors.WindowText; backColor = System.Drawing.SystemColors.Window; } public DrawItemEventArgs(Graphics graphics, Font font, Rectangle rect, int index, DrawItemState state, Color foreColor, Color backColor) { this.graphics = graphics; this.font = font; this.rect = rect; this.index = index; this.state = state; this.foreColor = foreColor; this.backColor = backColor; } public virtual void DrawBackground() { Brush brush = new SolidBrush(BackColor); Graphics.FillRectangle(brush, rect); brush.Dispose(); } public virtual void DrawFocusRectangle() { } } public delegate void DrawItemEventHandler(object sender, DrawItemEventArgs e); }