public static void FillPointer(Graphics g, Rectangle rect, int tipSize, int thickness, Color color, Color borderColor, float angle = 0.0f) { Color colorOther = DrawingUtils.BlendColors(color, Color.White, 1.0f); Brush background = new LinearGradientBrush(rect, colorOther, color, System.Drawing.Drawing2D.LinearGradientMode.Vertical); Pen borderPen = new Pen(borderColor); int x = rect.X; int y = rect.Y; int w = rect.Width; int h = rect.Height; GraphicsPath backgroundPath = new GraphicsPath(); backgroundPath.AddLine(x, y, x + w, y); backgroundPath.AddLine(x + w, y, x + w, y + h - tipSize); backgroundPath.AddLine(x + w, y + h - tipSize, x + w - thickness, y + h - tipSize); backgroundPath.AddLine(x + w - thickness, y + h - tipSize, x + w - thickness, y + thickness); backgroundPath.AddLine(x + w - thickness, y + thickness, x + thickness, y + thickness); backgroundPath.AddLine(x + thickness, y + thickness, x + thickness, y + h - tipSize); backgroundPath.AddLine(x + thickness, y + h - tipSize, x + w / 2, y + h - thickness); backgroundPath.AddLine(x + w / 2, y + h - thickness, x + w - thickness, y + h - tipSize); backgroundPath.AddLine(x + w - thickness, y + h - tipSize, x + w, y + h - tipSize); backgroundPath.AddLine(x + w, y + h - tipSize, x + w / 2, y + h); backgroundPath.AddLine(x + w / 2, y + h, x, y + h - tipSize); backgroundPath.AddLine(x, y + h - tipSize, x, y); backgroundPath.CloseFigure(); Matrix rotateMatrix = new Matrix(); rotateMatrix.Translate((x + w / 2), (y + h / 2)); rotateMatrix.Rotate(angle); rotateMatrix.Translate(-(x + w / 2), -(y + h / 2)); backgroundPath.Transform(rotateMatrix); g.SmoothingMode = SmoothingMode.AntiAlias; g.FillPath(background, backgroundPath); g.DrawPath(borderPen, backgroundPath); g.SmoothingMode = SmoothingMode.None; background.Dispose(); borderPen.Dispose(); backgroundPath.Dispose(); }
public static void FillRoundedRectangle(Graphics g, Rectangle rect, int radius, Color color, Corners roundedCorners, Color shadowColor, Point shadowOffset) { Color colorOther = DrawingUtils.BlendColors(color, Color.White, 1.0f); Brush background = new System.Drawing.Drawing2D.LinearGradientBrush(rect, colorOther, color, System.Drawing.Drawing2D.LinearGradientMode.Vertical); Brush shadow = new System.Drawing.SolidBrush(shadowColor); int x = rect.X; int y = rect.Y; int b = y + rect.Height; int r = x + rect.Width; GraphicsPath backgroundPath = new GraphicsPath(); if ((roundedCorners & Corners.C_UpperLeft) != 0) { // Draw rounded upper-left backgroundPath.AddArc(x, y, radius * 2, radius * 2, 180, 90); } else { // Draw flat upper-left backgroundPath.AddLine(x, y + radius, x, y); backgroundPath.AddLine(x, y, radius, y); } // Draw top backgroundPath.AddLine(x + radius, y, r - radius, y); if ((roundedCorners & Corners.C_UpperRight) != 0) { // Draw rounded upper-right backgroundPath.AddArc(r - radius * 2, y, radius * 2, radius * 2, 270, 90); } else { // Draw flat upper-right backgroundPath.AddLine(r - radius, y, r, y); backgroundPath.AddLine(r, y, r, y + radius); } // Draw right backgroundPath.AddLine(r, y + radius, r, b - radius); if ((roundedCorners & Corners.C_LowerRight) != 0) { // Draw rounded lower-right backgroundPath.AddArc(r - radius * 2, b - radius * 2, radius * 2, radius * 2, 0, 90); } else { // Draw flat lower-right backgroundPath.AddLine(r, b - radius, r, b); backgroundPath.AddLine(r, b, r - radius, b); } // Draw bottom backgroundPath.AddLine(r - radius, b, x + radius, b); if ((roundedCorners & Corners.C_LowerLeft) != 0) { // Draw rounded lower-left backgroundPath.AddArc(x, b - radius * 2, radius * 2, radius * 2, 90, 90); } else { // Draw flat lower-left backgroundPath.AddLine(x + radius, b, x, b); backgroundPath.AddLine(x, b, x, b - radius); } // Draw left backgroundPath.AddLine(x, b - radius, x, y + radius); backgroundPath.CloseFigure(); g.SmoothingMode = SmoothingMode.AntiAlias; g.FillPath(background, backgroundPath); if (shadowColor != null) { g.FillPath(shadow, backgroundPath); Matrix translateMatrix = new Matrix(); translateMatrix.Translate(shadowOffset.X, shadowOffset.Y); backgroundPath.Transform(translateMatrix); g.FillPath(background, backgroundPath); } g.SmoothingMode = SmoothingMode.None; background.Dispose(); shadow.Dispose(); backgroundPath.Dispose(); }