protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; using (GraphicsPath path = GraphicsTools.CreateRoundRectangle(this.ClientRectangle, 4)) { g.FillPath(new SolidBrush(Color.FromArgb(0xc8, 0xc8, 0xc8)), path); } updatePos(); }
private void DrawButtonBackground(Graphics g, Rectangle r, bool selected, bool pressed, bool checkd) { g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle border = new Rectangle(r.Left, r.Top, r.Width, r.Height); border.Inflate(-5, -5); if (selected || pressed || checkd) { using (GraphicsPath path = GraphicsTools.CreateRoundRectangle(border, ToolStripRadius)) { if (checkd) { using (SolidBrush sb = new SolidBrush(ToolStripColorTable.ToolStripButtonSelectedBackground)) { g.FillPath(sb, path); } using (Pen p = new Pen(ToolStripColorTable.ToolStripButtonSelectedBorder)) { g.DrawPath(p, path); } } else { using (SolidBrush sb = new SolidBrush(ToolStripColorTable.ToolStripButtonMoveBackground)) { g.FillPath(sb, path); } using (Pen p = new Pen(ToolStripColorTable.ToolStripButtonMoveBorder)) { g.DrawPath(p, path); } } } } }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { //base.OnPaint(e); Graphics g = e.Graphics; g.Clear(this.Parent.BackColor); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(Point.Empty, e.ClipRectangle.Size); rect.Width -= 1; rect.Height -= 1; Color coutBorder; Color cinnerBorder; Color cbackgroundTop; Color cbackgroundBottom; Color ctext; if (mouseover) { coutBorder = ButtonColor.HoverOutBorder; cinnerBorder = ButtonColor.HoverInnerBorder; cbackgroundTop = ButtonColor.HoverBackgroundTop; cbackgroundBottom = ButtonColor.HoverBackgroundBottom; ctext = mousedown ? Color.Black : ButtonColor.HoverText; } else { coutBorder = ButtonColor.OutBorder; cinnerBorder = ButtonColor.InnerBorder; cbackgroundTop = ButtonColor.BackgroundTop; cbackgroundBottom = ButtonColor.BackgroundBottom; ctext = ButtonColor.Text; } using (GraphicsPath path = GraphicsTools.CreateRoundRectangle(rect, 2)) { using (LinearGradientBrush lgBrush = new LinearGradientBrush(Point.Empty, new Point(rect.Width, rect.Height), cbackgroundTop, cbackgroundBottom)) { g.FillPath(lgBrush, path); } g.DrawPath(new Pen(coutBorder), path); rect.Inflate(-1, -1); using (GraphicsPath path2 = GraphicsTools.CreateRoundRectangle(rect, 2)) { g.DrawPath(new Pen(cinnerBorder), path2); } } StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; g.DrawString(this.Text, this.Font, new SolidBrush(ctext), e.ClipRectangle, sf); UpdateBounds(this.Location.X, this.Location.Y, this.Width, this.Height, e.ClipRectangle.Width, e.ClipRectangle.Height); }