public static void DrawPanel(Graphics g, Rectangle area, Color color, int borderSize) { // Border g.FillRectangle(new SolidBrush(DrawingPlus.DarkenColor(color, 64)), area); // Base area = new Rectangle(area.X + 1, area.Y + 1, area.Width - 2, area.Height - 2); g.FillRectangle(new SolidBrush(color), area); // Top g.FillRectangle(new SolidBrush(DrawingPlus.DarkenColor(color, -24)), new Rectangle(area.X, area.Y, area.Width, borderSize)); // Left g.FillRectangle(new SolidBrush(DrawingPlus.DarkenColor(color, -24)), new Rectangle(area.X, area.Y, borderSize, area.Height)); // Bottom g.FillRectangle(new SolidBrush(DrawingPlus.DarkenColor(color, 24)), new Rectangle(area.X, area.Y + area.Height - borderSize, area.Width, borderSize)); // Right g.FillRectangle(new SolidBrush(DrawingPlus.DarkenColor(color, 24)), new Rectangle(area.X + area.Width - borderSize, area.Y + borderSize, borderSize, area.Height - borderSize)); }
public static void DrawBorder(Graphics g, Rectangle area, Color color, int size) { if (size % 2 != 0) { size -= 1; } if (size < 2) { size = 2; } size -= 2; int b2size = 1; if (size == 0) { b2size = 0; size += 2; } g.FillRectangles(new SolidBrush(DrawingPlus.DarkenColor(color, 64)), new Rectangle[] { new Rectangle(area.X, area.Y, area.Width, b2size), new Rectangle(area.X, area.Y + b2size + size, area.Width, b2size), new Rectangle(area.X, area.Y, b2size, area.Height), new Rectangle(area.X + b2size + size, area.Y, b2size, area.Height), new Rectangle(area.X, area.Y + area.Height - b2size, area.Width, b2size), new Rectangle(area.X, area.Y + area.Height - b2size * 2 - size, area.Width, b2size), new Rectangle(area.X + area.Width - b2size, area.Y, b2size, area.Height), new Rectangle(area.X + area.Width - b2size * 2 - size, area.Y, b2size, area.Height) }); g.FillRectangles(new SolidBrush(DrawingPlus.DarkenColor(color, -24)), new Rectangle[] { new Rectangle(area.X + b2size, area.Y + b2size, area.Width - b2size * 2, size / 2), new Rectangle(area.X + b2size, area.Y + b2size, size / 2, area.Height - b2size * 2), new Rectangle(area.X + b2size, area.Y + area.Height - b2size - size, area.Width - b2size * 2, size / 2), new Rectangle(area.X + area.Width - b2size - size, area.Y + b2size, size / 2, area.Height - b2size * 2 - size), }); g.FillRectangles(new SolidBrush(DrawingPlus.DarkenColor(color, 24)), new Rectangle[] { new Rectangle(area.X + b2size + size / 2, area.Y + b2size + size / 2, area.Width - b2size * 2 - size / 2, size / 2), new Rectangle(area.X + b2size + size / 2, area.Y + b2size + size / 2, size / 2, area.Height - b2size * 2 - size / 2), new Rectangle(area.X + b2size + size / 2, area.Y + area.Height - b2size - size / 2, area.Width - b2size * 2 - size / 2, size / 2), new Rectangle(area.X + area.Width - b2size - size / 2, area.Y + 1 + size / 2, size / 2, area.Height - b2size * 2 - size / 2) }); }
public static void DrawBilinearHorizontalGradient(Graphics g, Rectangle area, Color color, float strength, bool flip = false) { Color color2 = DrawingPlus.DarkenColor(color, (int)(area.Height * strength)); Point pt1 = new Point(area.X, area.Y); Point pt2 = new Point(area.X, area.Y + area.Height / 2); LinearGradientBrush grd = new LinearGradientBrush(pt2, pt1, color, color2); if (flip == true) { grd = new LinearGradientBrush(pt1, pt2, color, color2); } grd.WrapMode = WrapMode.TileFlipXY; g.FillRectangle(grd, area); }
protected override void OnPaint(PaintEventArgs p) { Graphics g = p.Graphics; Rectangle r = new Rectangle(0, (base.Size.Height - 16) / 2, 16, 16); Brush fb; Color bg; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; if (Enabled) { fb = new SolidBrush(ForeColor); } else { fb = new SolidBrush(ColorTranslator.FromHtml("#A0A0A0")); } base.OnPaint(p); if (Clicked) { bg = DrawingPlus.DarkenColor(BoxColor, -32); } else if (Selected) { bg = DrawingPlus.DarkenColor(BoxColor, -16); } else { bg = BoxColor; } DrawingPlus.DrawBorder(g, r, BorderColor, 4); DrawingPlus.DrawPanel(g, new Rectangle(r.X + 4, r.Y + 4, r.X + r.Width - 8, r.Height - 8), bg, 2); if (this.Checked) { g.DrawString("✔", new Font("Lucida Console", 7), fb, r, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }); } }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; Font f = new Font(Font.FontFamily, Height / 3, Font.Style); Brush fb = new SolidBrush(ForeColor); Brush sb = new SolidBrush(ForeColor); Rectangle r = new Rectangle(0, 0, Width, Height); StringFormat sf = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; Color bg; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; if (Enabled == false) { fb = new SolidBrush(ColorTranslator.FromHtml("#A0A0A0")); } int brdSize; if (AutoSizeBorder) { brdSize = Math.Max(Math.Min(8, Height / 8), 4); if (brdSize % 2 != 0) { brdSize -= 1; } } else { brdSize = BorderSize; } if (Clicked) { bg = DrawingPlus.DarkenColor(BackColor, -32); } else if (Selected) { bg = DrawingPlus.DarkenColor(BackColor, -16); } else { bg = BackColor; } if (Clicked || Selected) { brdSize += 2; } DrawingPlus.DrawBorder(g, r, BorderColor, brdSize); DrawingPlus.DrawPanel(g, new Rectangle(brdSize, brdSize, Width - brdSize * 2, Height - brdSize * 2), bg, Math.Max(2, brdSize - 4)); if (ShadowColor != Color.Transparent) { g.DrawString(Text, f, Brushes.Black, new Rectangle(1, 1, Width, Height), sf); } g.DrawString(Text, f, fb, r, sf); }
protected override void OnPaint(PaintEventArgs e) { //base.OnPaint(e); Graphics g = e.Graphics; Rectangle rBrowse; Brush fb = new SolidBrush(ForeColor); Color bg; int brdSize = BorderSize; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; if (Enabled == false) { fb = new SolidBrush(ColorTranslator.FromHtml("#A0A0A0")); } if (Clicked) { bg = DrawingPlus.DarkenColor(BackColor, -32); } else if (Selected) { bg = DrawingPlus.DarkenColor(BackColor, -16); } else { bg = BackColor; } if (Clicked || Selected) { brdSize += 2; } rBrowse = new Rectangle(Width - Height + brdSize, brdSize, Height - brdSize * 2, Height - brdSize * 2); #region alternative design DrawingPlus.DrawBorder(g, new Rectangle(0, 0, Width - Height, Height), BorderColor, BorderSize); DrawingPlus.DrawPanel(g, new Rectangle( BorderSize, BorderSize, Width - Height - BorderSize * 2, Height - BorderSize * 2), BackColor, BorderSize - 2); DrawingPlus.DrawBorder(g, new Rectangle(Width - Height, 0, Height, Height), BorderColor, BorderSize); DrawingPlus.DrawPanel(g, new Rectangle( Width - Height + BorderSize, BorderSize, Height - BorderSize * 2, Height - borderSize * 2), BackColor, BorderSize - 2); #endregion DrawingPlus.DrawBorder(g, new Rectangle(0, 0, Width, Height), BorderColor, brdSize); DrawingPlus.DrawPanel(g, new Rectangle(brdSize, brdSize, Width - Height, Height - brdSize * 2), bg, Math.Max(2, brdSize - 4)); DrawingPlus.DrawPanel(g, rBrowse, bg, Math.Max(2, brdSize - 4)); StringFormat sf = new StringFormat(); StringFormat sfBrowse = new StringFormat(); sf.LineAlignment = StringAlignment.Center; sfBrowse.LineAlignment = StringAlignment.Center; sfBrowse.Alignment = StringAlignment.Center; Font fBrowse = new Font(Font.FontFamily, (int)(Font.Size * 0.66)); if (ShadowColor != Color.Transparent) { g.DrawString(Text, Font, Brushes.Black, new Rectangle(brdSize + 1, 1, Width, Height), sf); g.DrawString("▼", fBrowse, Brushes.Black, new Rectangle(rBrowse.X + 1, rBrowse.Y + 1, rBrowse.Width, rBrowse.Height), sfBrowse); } g.DrawString(Text, Font, fb, new Rectangle(brdSize, 0, Width, Height), sf); g.DrawString("▼", fBrowse, fb, rBrowse, sfBrowse); }