void DrawButton(PaintEventArgs e, ButtonInfo button, int iconX, int textX) { Color backColor = ButtonBackColor; Color foreColor = ButtonForeColor; if (button == PressedObject || button == HoverObject) { backColor = ButtonHoverBackColor; foreColor = ButtonHoverForeColor; } var rect = button.Bounds; var font = Font; e.Graphics.FillRectangle(new SolidBrush(backColor), rect); if (button.Image != null) { var rectIcon = new Rectangle(iconX, rect.Y, IconSize.Width, rect.Height); PaintHelper.DrawImageInRange(e.Graphics, button.Image, rectIcon); } if (!string.IsNullOrEmpty(button.Text)) { var rectText = new Rectangle(textX, rect.Y, rect.Right - textX, rect.Height); var sf = PaintHelper.SFLeft; sf.FormatFlags |= StringFormatFlags.NoWrap; sf.Trimming = StringTrimming.EllipsisCharacter; e.Graphics.DrawString(button.Text, Font, new SolidBrush(foreColor), rectText, sf); } }
void InvalidateButton(ButtonInfo button) { if (button != null) { Invalidate(button.Bounds); } }
void OnPressedObjectChanged(ButtonInfo old) { if (old != null) { InvalidateButton(old); } if (PressedObject != null) { InvalidateButton(PressedObject); } }
void OnHoverObjectChanged(ButtonInfo old) { if (old != null) { InvalidateButton(old); } if (HoverObject != null) { InvalidateButton(HoverObject); } }
void OnButtonClick(ButtonInfo button) { if (button == null) { throw new ArgumentNullException(); } button.NotifyClick(); if (ButtonClick != null) { ButtonClick(this, new ButtonEventArgs(button)); } }
public ButtonEventArgs(ButtonInfo button) { Button = button; }