//public System.Drawing.Rectangle ClientBounds //{ // get // { // new System.Drawing.Rectangle( // myBounds.Left + this.intLeftMargin, // myBounds.Top + this.intTopMargin, // myBounds.Width - this.intLeftMargin - this.intRightMargin, // myBounds.Height - this.intTopMargin - this.intBottomMargin); // } //} private System.Drawing.Drawing2D.GraphicsPath CreateShape() { return(ShapeDrawer.CreateRoundRectanglePath( new RectangleF( myBounds.Left, myBounds.Top, myBounds.Width, myBounds.Height), 30)); }
/// <summary> /// 绘制图形 /// </summary> /// <param name="g">画布对象</param> /// <param name="x">X坐标</param> /// <param name="y">Y坐标</param> public void Draw(System.Drawing.Graphics g, float x, float y) { using (System.Drawing.SolidBrush b = new SolidBrush(intBackColor)) { using (Pen p = new Pen(intBorderColor)) { ShapeDrawer drawer = new ShapeDrawer(); drawer.Bounds = new RectangleF(x - intSize / 2, y - intSize / 2, intSize, intSize); drawer.BorderPen = p; drawer.FillBrush = b; drawer.DrawAndFill(g); } } }
public static bool DrawRectangle( System.Drawing.Graphics g, System.Drawing.Pen BorderPen, System.Drawing.Brush FillBrush, System.Drawing.Rectangle Bounds, int roundRadio, System.Drawing.Rectangle ClipRectangle, bool ForceDrawBorder) { System.Drawing.Rectangle rect = System.Drawing.Rectangle.Empty; if (ClipRectangle.IsEmpty) { rect = Bounds; } else { rect = System.Drawing.Rectangle.Intersect(Bounds, ClipRectangle); } if (rect.IsEmpty) { return(false); } if (roundRadio <= 0) { if (FillBrush != null) { g.FillRectangle(FillBrush, rect); } if (BorderPen != null) { rect = new System.Drawing.Rectangle( Bounds.Left, Bounds.Top, Bounds.Width - (int)Math.Ceiling(BorderPen.Width / 2.0), Bounds.Height - (int)Math.Ceiling(BorderPen.Width / 2.0)); if (ForceDrawBorder || ClipRectangle.IsEmpty) { g.DrawRectangle(BorderPen, rect); } else { if (rect.IntersectsWith(ClipRectangle)) { g.DrawRectangle(BorderPen, rect); } } } } else { if (FillBrush != null) { int fix = 0; if (BorderPen != null) { fix = (int)Math.Ceiling(BorderPen.Width / 2.0); } using (GraphicsPath path = ShapeDrawer.CreateRoundRectanglePath( new RectangleF(Bounds.Left, Bounds.Top, Bounds.Width - fix, Bounds.Height - fix), roundRadio)) { g.FillPath(FillBrush, path); } } if (BorderPen != null) { using (GraphicsPath path = ShapeDrawer.CreateRoundRectanglePath( new RectangleF( Bounds.Left, Bounds.Top, Bounds.Width - ( int )Math.Ceiling(BorderPen.Width / 2.0), Bounds.Height - ( int)Math.Ceiling(BorderPen.Width / 2.0)), roundRadio)) { if (ForceDrawBorder || ClipRectangle.IsEmpty) { g.DrawPath(BorderPen, path); } else { if (rect.IntersectsWith(ClipRectangle)) { g.DrawPath(BorderPen, path); } } } } } return(true); }