public override int Paint(Graphics g, Rectangle bounds, DetourSelectionListStyle style) { Bounds = bounds; var myStyle = style.GetItemStyle(this); //if (Highlighted) // g.FillRectangle(myStyle.BackgroundBrush, bounds); string cancelText = Item.Canceled ? "Uncancel" : "Cancel"; Size cancelTextSize = TextRenderer.MeasureText(cancelText, myStyle.Font); Size textSize = TextRenderer.MeasureText(Text, style.Font); Rectangle textBox = new Rectangle(bounds.X + 3 + myStyle.Indent, bounds.Y + (bounds.Height - textSize.Height) / 2, textSize.Width, textSize.Height); _CancelBox = new Rectangle( textBox.Right + 3, bounds.Y + 2, cancelTextSize.Width + 6, bounds.Height - 4 ); Rectangle cancelTextBox = new Rectangle( _CancelBox.X + 3, _CancelBox.Y + (_CancelBox.Height - cancelTextSize.Height) / 2, cancelTextSize.Width, cancelTextSize.Height ); using (Brush b = Item.Canceled ? new SolidBrush(UncanceledColor) : new SolidBrush(CanceledColor)) g.FillRectangle(_CancelButtonHot ? myStyle.BackgroundBrush : b, _CancelBox); g.DrawRectangle(Pens.Black, _CancelBox); Painter.RenderText(g, myStyle.Font, cancelText, cancelTextBox, Color.White); Color c = Item.Canceled ? CanceledColor : myStyle.TextColor; if (Item.Canceled) { using (Font f = new Font(myStyle.Font, FontStyle.Strikeout)) Painter.RenderText(g, f, Text, textBox, c); } else { Painter.RenderText(g, myStyle.Font, Text, textBox, c); } return(bounds.Bottom); }
/// <summary> /// Renders the list item using the specified values /// </summary> /// <param name="g">The graphics object used to render the item</param> /// <param name="bounds">The bounds of the list item</param> /// <param name="font">The font used to render the text of the list item</param> /// <param name="background">The brush used to render the background of the item</param> /// <param name="textColor">The color used to render the text of the item</param> /// <param name="checkPen">The pen used to render the checkbox of the item</param> /// <param name="checkBrush">The brush used to render the background of the checkbox of the item</param> /// <param name="expandPen">The pen used to render the expand box of the item</param> /// <param name="expandBrush">The brush used to render the background of the expand box of the item</param> public virtual int Paint(Graphics g, Rectangle bounds, DetourSelectionListStyle style) { var myStyle = style.GetItemStyle(this); Bounds = bounds; ExpandBox = new Rectangle(bounds.X + 5 + myStyle.Indent, bounds.Y + (bounds.Height - 10) / 2, 10, 10); CheckBox = CheckBox = new Rectangle( ExpandBox.Right + 5, bounds.Y + (bounds.Height - CHECK_BOX_SIZE) / 2, CHECK_BOX_SIZE, CHECK_BOX_SIZE); Size textSize = TextRenderer.MeasureText(g, Text, myStyle.Font); Rectangle textRect = new Rectangle( CheckBox.Right + 2, bounds.Y + (bounds.Height - textSize.Height) / 2 + 1, bounds.Width - CheckBox.Width - 7, bounds.Height ); //paint list background g.FillRectangle(myStyle.BackgroundBrush, bounds); //render expand collapse box based on child count if (Children.Count > 0) { Painter.RenderExpandBox(g, ExpandBox, myStyle.ExpandPen, myStyle.ExpandBrush, Expanded); } Painter.RenderCheckBox(g, CheckBox, myStyle.CheckPen, myStyle.CheckBrush, Selected); Painter.RenderText(g, myStyle.Font, Text, textRect, myStyle.TextColor); int y = bounds.Bottom; if (Expanded) { Rectangle childBounds = new Rectangle(bounds.X, y, bounds.Width, bounds.Height); foreach (var child in Children) { y = child.Paint(g, childBounds, style); childBounds = new Rectangle(bounds.X, y, bounds.Width, bounds.Height); } } return(y); }