public static void Draw(BorderButton button, Graphics g) { //Apply the DrawingSettings button.DrawingSettings.Apply(g); //Draw Background var BackColor = button.MouseState != MouseState.MouseDown ? button.BackColor : button.BorderColor; if (button.MouseState == MouseState.Hover) { BackColor = BackColor.SetBrightness((float)Math.Max(0, Math.Min(1, BackColor.GetBrightness() * 2))); } g.Clear(BackColor); //Draw the Border g.DrawRectangle(new Pen(button.BorderColor, 2), new Rectangle(new Point(1, 1), new Size(button.Width - 2, button.Height - 2))); //Draw Text var TextColor = button.MouseState != MouseState.MouseDown ? button.BorderColor : button.ForeColor; g.DrawString(button.Text, button.Font, new SolidBrush(TextColor), button.ClientRectangle, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter }); }
private void Button_Paint(object sender, PaintEventArgs e) { BorderButton.Draw(this, e.Graphics); }