Beispiel #1
0
        private void DoRegion()
        {
            Region r = new Region(Rectangle.FromLTRB(0, 0, this.ClientSize.Width, this.ClientSize.Height));

            //r.Exclude(Rectangle.FromLTRB(10,10,50,50));

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            //gp.AddRectangle(Rectangle.FromLTRB(15,15,this.ClientSize.Width - 15,this.ClientSize.Height - 15));
            gp.StartFigure();
            gp.AddLine(0, 0, 15, 0);
            gp.AddLine(0, 0, 0, 15);
            gp.AddArc(0, 0, 31, 31, 180, 90);
            gp.CloseFigure();

            gp.StartFigure();
            gp.AddArc(0, this.ClientSize.Height - 30, 31, 31, 90, 90);
            gp.AddLine(0, this.ClientSize.Height, 0, this.ClientSize.Height - 15);
            gp.AddLine(0, this.ClientSize.Height, 15, this.ClientSize.Height);
            gp.CloseFigure();

            gp.StartFigure();
            gp.AddArc(this.ClientSize.Width - 30, this.ClientSize.Height - 30, 30, 30, 0, 90);
            gp.AddLine(this.ClientSize.Width, this.ClientSize.Height, this.ClientSize.Width, this.ClientSize.Height);
            gp.CloseFigure();

            gp.StartFigure();
            gp.AddArc(this.ClientSize.Width - 30, 0, 30, 30, 270, 90);
            gp.AddLine(this.ClientSize.Width, 0, this.ClientSize.Width, 0);
            gp.CloseFigure();

            r.Exclude(gp);

            this.Region = r;
        }
Beispiel #2
0
        private int _Radius = 50;  // 圆角弧度
        public void Round(System.Drawing.Region region)
        {
            System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath();
            int x          = 0;
            int y          = 0;
            int thisWidth  = this.Width;
            int thisHeight = this.Height;
            int angle      = _Radius;

            if (angle > 0)
            {
                System.Drawing.Graphics g = CreateGraphics();
                oPath.AddArc(x, y, angle, angle, 180, 90);                                 // 左上角
                oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90);                 // 右上角
                oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90);  // 右下角
                oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90);                 // 左下角
                oPath.CloseAllFigures();
                Region = new System.Drawing.Region(oPath);
            }
            else
            {
                oPath.AddLine(x + angle, y, thisWidth - angle, y);                         // 顶端
                oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle);        // 右边
                oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight);       // 底边
                oPath.AddLine(x, y + angle, x, thisHeight - angle);                        // 左边
                oPath.CloseAllFigures();
                Region = new System.Drawing.Region(oPath);
            }
        }
Beispiel #3
0
        public static Region DoRegion(int width, int height)
        {
            Region r = new Region(Rectangle.FromLTRB(0, 0, width, height));

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            gp.StartFigure();
            gp.AddLine(0, 0, 15, 0);
            gp.AddLine(0, 0, 0, 15);
            gp.AddArc(0, 0, 31, 31, 180, 90);
            gp.CloseFigure();

            gp.StartFigure();
            gp.AddArc(0, height - 30, 31, 31, 90, 90);
            gp.AddLine(0, height, 0, height - 15);
            gp.AddLine(0, height, 15, height);
            gp.CloseFigure();

            gp.StartFigure();
            gp.AddArc(width - 30, height - 30, 30, 30, 0, 90);
            gp.AddLine(width, height, width, height);
            gp.CloseFigure();

            gp.StartFigure();
            gp.AddArc(width - 30, 0, 30, 30, 270, 90);
            gp.AddLine(width, 0, width, 0);
            gp.CloseFigure();

            r.Exclude(gp);

            return(r);
        }
Beispiel #4
0
        /// <summary>
        /// 绘制圆角
        /// </summary>
        /// <param name="g"></param>
        /// <param name="p"></param>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="radius"></param>
        public static void DrawRoundRect(Graphics g, Pen p, Brush brush,float X, float Y, float width, float height, float radius)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddLine(X + radius, Y, X + width - (radius * 2), Y);

            gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90);

            gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2));

            gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90);

            gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height);

            gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90);

            gp.AddLine(X, Y + height - (radius * 2), X, Y + radius);

            gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90);

            gp.CloseFigure();

            g.DrawPath(p, gp);

            g.FillPath(brush, gp);

            gp.Dispose();
        }
Beispiel #5
0
        private System.Drawing.Drawing2D.GraphicsPath RoundRegion(Rectangle r)
        {
            //Scale the radius if it's too large to fit.
            int radius = CornerRadius;

            if (radius > (r.Width))
            {
                radius = r.Width;
            }
            if (radius > (r.Height))
            {
                radius = r.Height;
            }

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

            if (radius <= 0)
            {
                path.AddRectangle(r);
            }
            else
            {
                path.AddArc(r.Left, r.Top, radius, radius, 180, 90);
                path.AddArc(r.Right - radius, r.Top, radius, radius, 270, 90);
                path.AddLine(r.Right, r.Bottom, r.Right, r.Bottom);
                path.AddLine(r.Left, r.Bottom, r.Left, r.Bottom);
                path.CloseFigure();
            }

            return(path);
        }
Beispiel #6
0
        /// <summary>
        /// 划圆角边框
        /// </summary>
        /// <param name="g">绘制的图形</param>
        /// <param name="p">颜色和粗细</param>
        /// <param name="X">绘制图形的初始X</param>
        /// <param name="Y">绘制图形的初始Y</param>
        /// <param name="width">绘制图形的宽度</param>
        /// <param name="height">绘制图形的高度</param>
        /// <param name="radius">绘制图形的弧度</param>
        public void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddLine(X + radius, Y, X + width - (radius * 2), Y);

            gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90);

            gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2));

            gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90);

            gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height);

            gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90);

            gp.AddLine(X, Y + height - (radius * 2), X, Y + radius);

            gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90);

            gp.CloseFigure();

            g.DrawPath(p, gp);

            gp.Dispose();
        }
        public static System.Drawing.Drawing2D.GraphicsPath CreateRoundedRectPath(float x, float y, float width, float height, float radius)
        {
            var xw   = x + width;
            var yh   = y + height;
            var xwr  = xw - radius;
            var yhr  = yh - radius;
            var xr   = x + radius;
            var yr   = y + radius;
            var r2   = radius * 2;
            var xwr2 = xw - r2;
            var yhr2 = yh - r2;

            var p = new System.Drawing.Drawing2D.GraphicsPath();

            p.StartFigure();

            p.AddArc(x, y, r2, r2, 180, 90);

            p.AddLine(xr, y, xwr, y);

            p.AddArc(xwr2, y, r2, r2, 270, 90);

            p.AddLine(xw, yr, xw, yhr);

            p.AddArc(xwr2, yhr2, r2, r2, 0, 90);

            p.AddLine(xwr, yh, xr, yh);

            p.AddArc(x, yhr2, r2, r2, 90, 90);
            p.AddLine(x, yhr, x, yr);

            p.CloseFigure();
            return(p);
        }
Beispiel #8
0
 /// <summary>
 /// 角の丸い枠線を表すGraphicsPathを取得します
 /// </summary>
 /// <returns></returns>
 private System.Drawing.Drawing2D.GraphicsPath getGraphicsPath()
 {
     if (graphicsPath == null)
     {
         graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
         graphicsPath.StartFigure();
         int w = base.Width - 1;
         int h = base.Height - 1;
         // 上の横線
         graphicsPath.AddLine(RADIUS, 0, w - RADIUS, 0);
         // 右上の角
         graphicsPath.AddArc(w - DIAMETER, 0, DIAMETER, DIAMETER, 270, 90);
         // 右の縦線
         graphicsPath.AddLine(w, RADIUS, w, h - RADIUS);
         // 右下の角
         graphicsPath.AddArc(w - DIAMETER, h - DIAMETER, DIAMETER, DIAMETER, 0, 90);
         // 下の横線
         graphicsPath.AddLine(w - RADIUS, h, RADIUS, h);
         // 左下の角
         graphicsPath.AddArc(0, h - DIAMETER, DIAMETER, DIAMETER, 90, 90);
         // 左の縦線
         graphicsPath.AddLine(0, h - RADIUS, 0, RADIUS);
         // 左上の角
         graphicsPath.AddArc(0, 0, DIAMETER, DIAMETER, 180, 90);
         graphicsPath.CloseFigure();
     }
     return(graphicsPath);
 }
Beispiel #9
0
        private System.Drawing.Drawing2D.GraphicsPath RoundedRect(Vector2 p1, Vector2 p2, float radius)
        {
            float diameter = radius * 2;

            System.Drawing.SizeF                  size = new System.Drawing.SizeF(diameter, diameter);
            System.Drawing.RectangleF             arc  = new System.Drawing.RectangleF(new System.Drawing.PointF(p1.x, p1.y), size);
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

            /*if (radius == 0)
             * {
             *  path.AddRectangle(bounds);
             *  return path;
             * }*/

            // top left arc
            path.AddArc(arc, 180, 90);

            // top right arc
            arc.X = p2.x - diameter;
            path.AddArc(arc, 270, 90);

            // bottom right arc
            arc.Y = p2.y - diameter;
            path.AddArc(arc, 0, 90);

            // bottom left arc
            arc.X = p1.x;
            path.AddArc(arc, 90, 90);

            path.CloseFigure();
            return(path);
        }
        private void DrawTextBox(ref Bitmap bmp)
        {
            Graphics g = Graphics.FromImage(bmp);

            int       cRadius   = bmp.Width * 5 / 400;
            int       boxWidth  = bmp.Width;
            int       boxHeight = bmp.Height / 6;
            Rectangle rect      = new Rectangle(cRadius / 2, cRadius / 2, boxWidth - cRadius, boxHeight - cRadius);

            // 指定图形路径, 有一系列 直线/曲线 组成
            System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath();
            myPath.StartFigure();
            myPath.AddArc(new Rectangle(new Point(rect.X, rect.Y), new Size(2 * cRadius, 2 * cRadius)), 180, 90);
            myPath.AddLine(new Point(rect.X + cRadius, rect.Y), new Point(rect.Right - cRadius, rect.Y));
            myPath.AddArc(new Rectangle(new Point(rect.Right - 2 * cRadius, rect.Y), new Size(2 * cRadius, 2 * cRadius)), 270, 90);
            myPath.AddLine(new Point(rect.Right, rect.Y + cRadius), new Point(rect.Right, rect.Bottom - cRadius));
            myPath.AddArc(new Rectangle(new Point(rect.Right - 2 * cRadius, rect.Bottom - 2 * cRadius), new Size(2 * cRadius, 2 * cRadius)), 0, 90);
            myPath.AddLine(new Point(rect.Right - cRadius, rect.Bottom), new Point(rect.X + cRadius, rect.Bottom));
            myPath.AddArc(new Rectangle(new Point(rect.X, rect.Bottom - 2 * cRadius), new Size(2 * cRadius, 2 * cRadius)), 90, 90);
            myPath.AddLine(new Point(rect.X, rect.Bottom - cRadius), new Point(rect.X, rect.Y + cRadius));
            myPath.CloseFigure();

            int opacity = 50;
            int alpha   = (opacity * 255) / 100;

            g.FillPath(new SolidBrush(Color.FromArgb(alpha, Color.AliceBlue)), myPath);

            float fontSize = boxHeight * 25 / 80;
            int   stringX  = bmp.Width * 5 / 400;
            int   stringY  = (int)((boxHeight - fontSize / 72 * 96) / 3);

            g.DrawString(DateTime.Now.ToString("hh:mm:ss"), new Font("Segoe UI", fontSize),
                         new SolidBrush(Color.Green), stringX, stringY);
        }
        public override void AddTabBorder(System.Drawing.Drawing2D.GraphicsPath path, System.Drawing.Rectangle tabBounds)
        {
            switch (this._TabControl.Alignment)
            {
            case TabAlignment.Top:
                path.AddLine(tabBounds.X, tabBounds.Bottom, tabBounds.X + tabBounds.Height - 4, tabBounds.Y + 2);
                path.AddLine(tabBounds.X + tabBounds.Height, tabBounds.Y, tabBounds.Right - 3, tabBounds.Y);
                path.AddArc(tabBounds.Right - 6, tabBounds.Y, 6, 6, 270, 90);
                path.AddLine(tabBounds.Right, tabBounds.Y + 3, tabBounds.Right, tabBounds.Bottom);
                break;

            case TabAlignment.Bottom:
                path.AddLine(tabBounds.Right, tabBounds.Y, tabBounds.Right, tabBounds.Bottom - 3);
                path.AddArc(tabBounds.Right - 6, tabBounds.Bottom - 6, 6, 6, 0, 90);
                path.AddLine(tabBounds.Right - 3, tabBounds.Bottom, tabBounds.X + tabBounds.Height, tabBounds.Bottom);
                path.AddLine(tabBounds.X + tabBounds.Height - 4, tabBounds.Bottom - 2, tabBounds.X, tabBounds.Y);
                break;

            case TabAlignment.Left:
                path.AddLine(tabBounds.Right, tabBounds.Bottom, tabBounds.X + 3, tabBounds.Bottom);
                path.AddArc(tabBounds.X, tabBounds.Bottom - 6, 6, 6, 90, 90);
                path.AddLine(tabBounds.X, tabBounds.Bottom - 3, tabBounds.X, tabBounds.Y + tabBounds.Width);
                path.AddLine(tabBounds.X + 2, tabBounds.Y + tabBounds.Width - 4, tabBounds.Right, tabBounds.Y);
                break;

            case TabAlignment.Right:
                path.AddLine(tabBounds.X, tabBounds.Y, tabBounds.Right - 2, tabBounds.Y + tabBounds.Width - 4);
                path.AddLine(tabBounds.Right, tabBounds.Y + tabBounds.Width, tabBounds.Right, tabBounds.Bottom - 3);
                path.AddArc(tabBounds.Right - 6, tabBounds.Bottom - 6, 6, 6, 0, 90);
                path.AddLine(tabBounds.Right - 3, tabBounds.Bottom, tabBounds.X, tabBounds.Bottom);
                break;
            }
        }
Beispiel #12
0
        private void roundObject(Form obj)
        {
            System.Drawing.Drawing2D.GraphicsPath DGP = new System.Drawing.Drawing2D.GraphicsPath();
            DGP.StartFigure();
            //'top left corner
            DGP.AddArc(new Rectangle(0, 0, 40, 40), 180, 90);
            DGP.AddLine(40, 0, obj.Width - 40, 0);


            //'top right corner
            DGP.AddArc(new Rectangle(obj.Width - 40, 0, 40, 40), -90, 90);
            DGP.AddLine(obj.Width, 40, obj.Width, obj.Height - 40);


            //'buttom right corner
            DGP.AddArc(new Rectangle(obj.Width - 40, obj.Height - 40, 40, 40), 0, 90);
            DGP.AddLine(obj.Width - 40, obj.Height, 40, obj.Height);


            //'buttom left corner
            DGP.AddArc(new Rectangle(0, obj.Height - 40, 40, 40), 90, 90);
            DGP.CloseFigure();

            obj.Region = new Region(DGP);
        }
Beispiel #13
0
 // 圆角代码
 public void Round(System.Drawing.Region region)
 {
     // -----------------------------------------------------------------------------------------------
     // 已经是.net提供给我们的最容易的改窗体的属性了(以前要自己调API)
     System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath();
     int x = 0;
     int y = 0;
     int thisWidth = this.Width;
     int thisHeight = this.Height;
     int angle = _Radius;
     if (angle > 0)
     {
         System.Drawing.Graphics g = CreateGraphics();
         oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角
         oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角
         oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角
         oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角
         oPath.CloseAllFigures();
         Region = new System.Drawing.Region(oPath);
     }
     // -----------------------------------------------------------------------------------------------
     else
     {
         oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端
         oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边
         oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边
         oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边
         oPath.CloseAllFigures();
         Region = new System.Drawing.Region(oPath);
     }
 }
Beispiel #14
0
        // 圆角代码 第一个参数是该元素的宽,第二个参数是元素的高,第三个参数是圆角半径
        public Region Round(int width, int height, int _Radius)
        {
            System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath();
            int x          = 1;
            int y          = 1;
            int thisWidth  = width;
            int thisHeight = height;
            int angle      = _Radius;

            if (angle > 0)
            {
                System.Drawing.Graphics g = CreateGraphics();
                oPath.AddArc(x, y, angle, angle, 180, 90);                                // 左上角
                oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90);                // 右上角
                oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角
                oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90);                // 左下角

                oPath.CloseAllFigures();
                return(new System.Drawing.Region(oPath));
            }
            // -----------------------------------------------------------------------------------------------
            else
            {
                oPath.AddLine(x + angle, y, thisWidth - angle, y);                   // 顶端
                oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle);  // 右边
                oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边
                oPath.AddLine(x, y + angle, x, thisHeight - angle);                  // 左边
                oPath.CloseAllFigures();
                return(new System.Drawing.Region(oPath));
            }
        }
        void DrawPill(Graphics G, Pen P, Brush B, Brush B2, float x, float y, float width, float height, float fill, PillStyle style)
        {
            float H = height - width;

            float radius = width / 2.0f;

            switch (style)
            {
            case PillStyle.Bipolar:
            {
                if (fill > 0)
                {
                    var FPath = new System.Drawing.Drawing2D.GraphicsPath();
                    // FPath.AddArc(x, y, width, width, 180, 180);

                    FPath.AddLine(x + width, y + radius + 0.5f * (height - width), x + width, y + radius + (height - width - radius) * (fill * 0.5f + 0.5f));
                    //  if (fill >= 0.9)
                    // {
                    FPath.AddArc(x, y + radius + (height - width - radius) * (fill * 0.5f + 0.5f), width, width, 0, 180);
                    // }
                    FPath.AddLine(x, y + radius + (height - width - radius) * (fill * 0.5f + 0.5f), x, y + radius + 0.5f * (height - width));

                    //G.FillPath(B, FPath);
                    //x -= 50.0f;
                    G.FillPath(B, FPath);
                }
                else
                {
                    fill = 1 + fill;
                    var FPath = new System.Drawing.Drawing2D.GraphicsPath();

                    FPath.AddArc(x, y + (fill * 0.5f) * (height - width), width, width, 180, 180);
                    FPath.AddLine(x + width, y + (fill * 0.5f + 0.5f) * (height - width), x + width, y + radius + (height - width) * 0.5f);
                    FPath.AddLine(x, y + radius + 0.5f * (height - width), x, y + radius + (height - width) * (fill * 0.5f + 0.5f));


                    G.FillPath(B2, FPath);
                }
            }
            break;

            case PillStyle.Positive:
                break;

            case PillStyle.Negative:
                break;
            }


            var Path = new System.Drawing.Drawing2D.GraphicsPath();

            Path.AddArc(x, y, width, width, 180, 180);

            Path.AddLine(x + width, y + radius, x + width, y + height - radius);
            Path.AddArc(x, y + H, width, width, 0, 180);
            Path.AddLine(x, y + height - radius, x, y + radius);

            G.DrawPath(P, Path);
        }
Beispiel #16
0
        private DialogResult PopupInput(ListViewItem.ListViewSubItem pSelectedSubItems, int border, int length, ref string output)
        {
            System.Drawing.Point ctrlpt = pSelectedSubItems.Bounds.Location;
            ctrlpt = this.PointToScreen(pSelectedSubItems.Bounds.Location);
            //ctrlpt.Y += grbSave.Location.Y + 10;
            //ctrlpt.X += grbSave.Location.X + (length / 2);
            ctrlpt.Y += 251;
            ctrlpt.X += 328 + (length / 2);
            TextBox input = new TextBox {
                Height = 20, Width = length, Top = border / 2, Left = border / 2
            };

            input.BorderStyle = BorderStyle.FixedSingle;
            input.Text        = output;

            //######## SetColor to your preference
            input.BackColor = Color.Azure;

            Button btnok = new Button {
                DialogResult = System.Windows.Forms.DialogResult.OK, Top = 25
            };
            Button btncn = new Button {
                DialogResult = System.Windows.Forms.DialogResult.Cancel, Top = 25
            };

            Form frm = new Form {
                ControlBox = false, AcceptButton = btnok, CancelButton = btncn, StartPosition = FormStartPosition.Manual, Location = ctrlpt
            };

            frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            //######## SetColor to your preference
            frm.BackColor = Color.Black;

            RectangleF rec = new RectangleF(0, 0, (length + border), (20 + border));

            System.Drawing.Drawing2D.GraphicsPath GP = new System.Drawing.Drawing2D.GraphicsPath(); //GetRoundedRect(rec, 4.0F);
            float      diameter = 8.0F;
            SizeF      sizef    = new SizeF(diameter, diameter);
            RectangleF arc      = new RectangleF(rec.Location, sizef);

            GP.AddArc(arc, 180, 90);
            arc.X = rec.Right - diameter;
            GP.AddArc(arc, 270, 90);
            arc.Y = rec.Bottom - diameter;
            GP.AddArc(arc, 0, 90);
            arc.X = rec.Left;
            GP.AddArc(arc, 90, 90);
            GP.CloseFigure();

            frm.Region = new Region(GP);
            frm.Controls.AddRange(new Control[] { input, btncn, btnok });
            DialogResult rst = frm.ShowDialog();

            output = input.Text;
            return(rst);
        }
Beispiel #17
0
 public static System.Drawing.Drawing2D.GraphicsPath  RoundRectangle(Rectangle R, int Curve)
 {
     System.Drawing.Drawing2D.GraphicsPath GP = new System.Drawing.Drawing2D.GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding);
     GP.AddArc(R.X, R.Y, Curve, Curve, 180.0F, 90.0F);
     GP.AddArc(R.Right - Curve, R.Y, Curve, Curve, 270.0F, 90.0F);
     GP.AddArc(R.Right - Curve, R.Bottom - Curve, Curve, Curve, 0.0F, 90.0F);
     GP.AddArc(R.X, R.Bottom - Curve, Curve, Curve, 90.0F, 90.0F);
     GP.CloseFigure();
     return(GP);
 }
Beispiel #18
0
 public static System.Drawing.Drawing2D.GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius)
 {
     System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
     path.AddArc(x, y, radius, radius, 180f, 90f);
     path.AddArc(width - radius, y, radius, radius, 270f, 90f);
     path.AddArc(width - radius, height - radius, radius, radius, 0f, 90f);
     path.AddArc(x, height - radius, radius, radius, 90f, 90f);
     path.CloseAllFigures();
     return(path);
 }
Beispiel #19
0
 public static System.Drawing.Drawing2D.GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius)
 {
     System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
     path.AddArc(x, y, radius, radius, 180f, 90f);
     path.AddArc(width - radius, y, radius, radius, 270f, 90f);
     path.AddArc(width - radius, height - radius, radius, radius, 0f, 90f);
     path.AddArc(x, height - radius, radius, radius, 90f, 90f);
     path.CloseAllFigures();
     return path;
 }
        public void DrawMarkings(Graphics graphics)
        {
            // Create the pen for drawing the field lines with
            using (Pen linePen = new Pen(Color.Brown, linePenWidth)) {
                using (Brush courtBrush = new SolidBrush(Color.LightGray)) {
                    #region Draw the court surface
                    using (var path = new System.Drawing.Drawing2D.GraphicsPath()) {
                        float pos_frame_rad = 2.0F;
                        path.AddArc(new RectangleF(0.0F, 0.0F, (pos_frame_rad * 2), (pos_frame_rad * 2)), -180.0F, 90.0F);
                        path.AddArc(new RectangleF(Length - (pos_frame_rad * 2), 0.0F, (pos_frame_rad * 2), (pos_frame_rad * 2)), 270.0F, 90.0F);
                        path.AddArc(new RectangleF(Length - (pos_frame_rad * 2), Width - (pos_frame_rad * 2), (pos_frame_rad * 2), (pos_frame_rad * 2)), 0.0F, 90.0F);
                        path.AddArc(new RectangleF(0.0F, Width - (pos_frame_rad * 2), (pos_frame_rad * 2), (pos_frame_rad * 2)), 90.0F, 90.0F);
                        path.CloseFigure();
                        linePen.Width *= 2.0F;
                        graphics.DrawPath(linePen, path);
                        linePen.Width /= 2.0F;
                    }
                    #endregion

                    #region Draw central line
                    PointF fieldCenter      = new PointF(Length / 2, Width / 2);
                    PointF centerLineTop    = new PointF(fieldCenter.X, 0.0F);
                    PointF centerLineBottom = new PointF(fieldCenter.X, Width);
                    PointF leftLineTop      = new PointF(2.5F, 0.0F);
                    PointF leftLineBottom   = new PointF(2.5F, Width);
                    PointF rightLineTop     = new PointF(Length - 2.5F, 0.0F);
                    PointF rightLineBottom  = new PointF(Length - 2.5F, Width);

                    graphics.DrawLine(linePen, centerLineTop, centerLineBottom);
                    graphics.DrawLine(linePen, leftLineTop, leftLineBottom);
                    graphics.DrawLine(linePen, rightLineTop, rightLineBottom);
                    #endregion

                    #region Draw goal lines
                    DrawGoal(graphics, linePen, 3.0F - 0.5F, Width / 2.0F, true);
                    DrawGoal(graphics, linePen, Length - 3.0F + 0.5F, Width / 2.0F, !true);
                    #endregion Draw goal lines

                    #region Draw bully line
                    using (Pen bullyPen = new Pen(Color.Black, 0.09F)) {
                        DrawingCross(graphics, bullyPen, Length / 2.0F, 1.0F);
                        DrawingCross(graphics, bullyPen, HalfLength, HalfWidth);
                        DrawingCross(graphics, bullyPen, Length / 2.0F, Width - 1.0F);

                        DrawingCross(graphics, bullyPen, 2.5F, 1.0F);
                        DrawingCross(graphics, bullyPen, 2.5F, Width - 1.0F);

                        DrawingCross(graphics, bullyPen, Length - 2.5F, 1.0F);
                        DrawingCross(graphics, bullyPen, Length - 2.5F, Width - 1.0F);
                    }
                    #endregion Draw bully line
                }
            }
        }
        public void EditPicture(ref PictureBox pictureEdit, int Curvature)
        {
            Rectangle r = new Rectangle(0, 0, pictureEdit.Width, pictureEdit.Height);

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            gp.AddArc(r.X, r.Y, Curvature, Curvature, 180, 90);
            gp.AddArc(r.X + r.Width - Curvature, r.Y, Curvature, Curvature, 270, 90);
            gp.AddArc(r.X + r.Width - Curvature, r.Y + r.Height - Curvature, Curvature, Curvature, 0, 90);
            gp.AddArc(r.X, r.Y + r.Height - Curvature, Curvature, Curvature, 90, 90);
            pictureEdit.Region = new Region(gp);
        }
Beispiel #22
0
 private void CreateBody()
 {
     gp = new System.Drawing.Drawing2D.GraphicsPath();
     gp.AddArc(location.X, location.Y, 30.0F, 30.0F, 180, 180);
     gp.AddLine(new PointF(location.X + 30.0F, location.Y + 15.0F), new PointF(location.X + 30.0F, location.Y + 30.0F));
     gp.AddLine(new PointF(location.X + 30.0F, location.Y + 30.0F), new PointF(location.X + 28.5F, location.Y + 30.0F));
     gp.AddArc(location.X + 16.5F, location.Y + 17.0F, 12.0F, 26.0F, 180, 180);
     gp.AddLine(new PointF(location.X + 16.5F, location.Y + 30.0F), new PointF(location.X + 13.5F, location.Y + 30.0F));
     gp.AddArc(location.X + 1.5F, location.Y + 17.0F, 12.0F, 26.0F, 180, 180);
     gp.AddLine(new PointF(location.X + 1.5F, location.Y + 30.0F), new PointF(location.X, location.Y + 30.0F));
     //gp.AddLine(new PointF(location.X, location.Y + 30.0F), new PointF(location.X, location.Y + 15.0F));
 }
Beispiel #23
0
        ///
        //public PointLatLng OtstupVPP(double distOtst, int mode, PointLatLng FRMPoint)
        //{
        //    double len = Math.Cos(FRMPoint.Lat * Math.PI / 180) * 40000 / 360;
        //    double x = 0;
        //    double y = 0;
        //    switch (mode)
        //    {
        //        case 1: //-90
        //            {
        //                x = FRMPoint.Lng + distOtst * Math.Cos((180 - 61) * Math.PI / 180) / len; // 90 - 61 + 270 + 180
        //                y = FRMPoint.Lat + distOtst * Math.Sin((180 - 61) * Math.PI / 180) / 111.1;
        //                break;
        //            }
        //        case 2: //0
        //            {
        //                x = FRMPoint.Lng + distOtst * Math.Cos((90 - 61) * Math.PI / 180) / len;
        //                y = FRMPoint.Lat + distOtst * Math.Sin((90 - 61) * Math.PI / 180) / 111.1;
        //                break;
        //            }
        //        case 3:  // 90
        //            {
        //                x = FRMPoint.Lng + distOtst * Math.Cos((360 - 61) * Math.PI / 180) / len;//90-61+270
        //                y = FRMPoint.Lat + distOtst * Math.Sin((360 - 61) * Math.PI / 180) / 111.1;
        //                break;
        //            }
        //        case 4:      //180
        //            {
        //                x = FRMPoint.Lng + distOtst * Math.Cos((270 - 61) * Math.PI / 180) / len; //90-61+180
        //                y = FRMPoint.Lat + distOtst * Math.Sin((270 - 61) * Math.PI / 180) / 111.1;
        //                break;
        //            }
        //        default: break;

        //    }

        //    return new PointLatLng(y, x);

        //}
        /// ///////////////

        public override void OnRender(Graphics g)
        {
            int R = (int)((Radius) / Overlay.Control.MapProvider.Projection.GetGroundResolution((int)Overlay.Control.Zoom, Position.Lat)) * 2;

            ///new
            int twidth  = (int)((3061.2188) / Overlay.Control.MapProvider.Projection.GetGroundResolution((int)Overlay.Control.Zoom, Position.Lat));
            int theight = (int)((1696.8336) / Overlay.Control.MapProvider.Projection.GetGroundResolution((int)Overlay.Control.Zoom, Position.Lat));

            //int twidth = (int)((3061.2188) / Overlay.Control.MapProvider.Projection.GetGroundResolution((int)Overlay.Control.Zoom, Position.Lat));
            //int theight = (int)((1696.8336) / Overlay.Control.MapProvider.Projection.GetGroundResolution((int)Overlay.Control.Zoom, Position.Lat));

            int x          = LocalPosition.X - R / 2;
            int y          = LocalPosition.Y - R / 2;
            int width      = R;
            int height     = R;
            int startAngle = 61;
            int sweepAngle = 180;


            if (IsFilled)
            {
                if (CirleState)
                {
                    g.FillEllipse(Fill, new System.Drawing.Rectangle(LocalPosition.X - R / 2, LocalPosition.Y - R / 2, R, R));
                }
                else
                {
                    System.Drawing.Drawing2D.GraphicsPath path1 = new System.Drawing.Drawing2D.GraphicsPath();

                    path1.AddArc(x, y, width, height, startAngle, sweepAngle);

                    g.FillPath(Fill, path1);
                    g.DrawPath(Stroke, path1);
                }
            }
            if (CirleState)
            {
                g.DrawEllipse(Stroke, new System.Drawing.Rectangle(LocalPosition.X - R / 2, LocalPosition.Y - R / 2, R, R));
            }
            else

            {
                System.Drawing.Drawing2D.GraphicsPath path2 = new System.Drawing.Drawing2D.GraphicsPath();
                Pen blackPen = new Pen(Color.Black, 3);

                path2.AddArc(x, y, width, height, startAngle, sweepAngle);
                path2.AddArc(x + twidth, y - theight, width, height, startAngle - 180, sweepAngle);
                path2.AddArc(x, y, width, height, startAngle, sweepAngle);

                g.FillPath(Fill, path2);
                g.DrawPath(Stroke, path2);
            }
        }
        public static void BordesRedondeados(Button b)
        {
            Rectangle r = new Rectangle(0, 0, b.Width, b.Height);

            System.Drawing.Drawing2D.GraphicsPath button = new System.Drawing.Drawing2D.GraphicsPath();
            int d = 10; // VARIABLE CONTROL PARA N CONTORNO REDONDEADO DE BOTONES

            button.AddArc(r.X, r.Y, d, d, 180, 90);
            button.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90);
            button.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
            button.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90);
            b.Region = new Region(button);
        }
Beispiel #25
0
        private void button1_Click(object sender, EventArgs e)
        {
            Rectangle r = new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height);

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            int d = 50;

            gp.AddArc(r.X, r.Y, d, d, 180, 90);
            gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90);
            gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
            gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90);
            pictureBox1.Region = new Region(gp);
        }
Beispiel #26
0
        public void OvalKenar()// Oval kenarlı PİCTURBOX İÇİN GÖRÜNTÜ AYARLARI
        {
            Rectangle r = new Rectangle(0, 0, pictureBoxKisiFotosu.Width, pictureBoxKisiFotosu.Height);

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            int d = 172;

            gp.AddArc(r.X, r.Y, d, d, 180, 90);
            gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90);
            gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
            gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90);
            pictureBoxKisiFotosu.Region = new Region(gp);
        }//// OvalKenar() end
 static void DrawRoundedRectangle(Graphics g, Pen p, int x, int y, int w, int h, int rx, int ry)
 {
     System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
     path.AddArc(x, y, rx + rx, ry + ry, 180, 90);
     path.AddLine(x + rx, y, x + w - rx, y);
     path.AddArc(x + w - 2 * rx, y, 2 * rx, 2 * ry, 270, 90);
     path.AddLine(x + w, y + ry, x + w, y + h - ry);
     path.AddArc(x + w - 2 * rx, y + h - 2 * ry, rx + rx, ry + ry, 0, 91);
     path.AddLine(x + rx, y + h, x + w - rx, y + h);
     path.AddArc(x, y + h - 2 * ry, 2 * rx, 2 * ry, 90, 91);
     path.CloseFigure();
     g.DrawPath(p, path);
 }
Beispiel #28
0
 /// <summary>
 /// Overrides <see cref="CADability.Curve2D.GeneralCurve2D.AddToGraphicsPath (System.Drawing.Drawing2D.GraphicsPath, bool)"/>
 /// </summary>
 /// <param name="path"></param>
 /// <param name="forward"></param>
 public override void AddToGraphicsPath(System.Drawing.Drawing2D.GraphicsPath path, bool forward)
 {
     if (forward)
     {
         path.AddArc((float)(Center.x - Radius), (float)(Center.y - Radius), (float)(2 * Radius),
                     (float)(2 * Radius), (float)(start.Degree), (float)(sweep.Degree));
     }
     else
     {
         path.AddArc((float)(Center.x - Radius), (float)(Center.y - Radius), (float)(2 * Radius),
                     (float)(2 * Radius), (float)((start + sweep).Degree), (float)(-sweep.Degree));
     }
 }
Beispiel #29
0
 void DrawRoundRect(Graphics g, Brush b, int x, int y, int w, int h, int r)
 {
     System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
     path.AddArc(x, y, r + r, r + r, 180, 90);
     path.AddLine(x + r, y, x + w - r, y);
     path.AddArc(x + w - 2 * r, y, 2 * r, 2 * r, 270, 90);
     path.AddLine(x + w, y + r, x + w, y + h - r);
     path.AddArc(x + w - 2 * r, y + h - 2 * r, r + r, r + r, 0, 91);
     path.AddLine(x + r, y + h, x + w - r, y + h);
     path.AddArc(x, y + h - 2 * r, 2 * r, 2 * r, 90, 91);
     path.CloseFigure();
     g.FillPath(b, path);
 }
        public static void BordeRedondo(Button b)
        {
            Rectangle r = new Rectangle(0, 0, b.Width, b.Height);

            System.Drawing.Drawing2D.GraphicsPath button = new System.Drawing.Drawing2D.GraphicsPath();
            int d = 10;

            button.AddArc(r.X, r.Y, d, d, 180, 90);
            button.AddArc(r.X + r.Width - d, r.Y, d, d, 300, 90);
            button.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
            button.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90);
            b.Region = new Region(button);
        }
Beispiel #31
0
 //Rounded Controls
 private static void SetRoundedShape(Control control, int radius)
 {
     System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
     path.AddLine(radius, 0, control.Width - radius, 0);
     path.AddArc(control.Width - radius, 0, radius, radius, 270, 90);
     path.AddLine(control.Width, radius, control.Width, control.Height - radius);
     path.AddArc(control.Width - radius, control.Height - radius, radius, radius, 0, 90);
     path.AddLine(control.Width - radius, control.Height, radius, control.Height);
     path.AddArc(0, control.Height - radius, radius, radius, 90, 90);
     path.AddLine(0, control.Height - radius, 0, radius);
     path.AddArc(0, 0, radius, radius, 180, 90);
     control.Region = new System.Drawing.Region(path);
 }
Beispiel #32
0
        public void Rounded()
        {
            Rectangle r = new Rectangle(0, 0, pictureBox2.Width, pictureBox2.Height);

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            int d = 55;

            gp.AddArc(r.X, r.Y, d, d, 180, 90);
            gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90);
            gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
            gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90);
            pictureBox2.Region = new Region(gp);
        }
Beispiel #33
0
        public PictureBox CornersRounded(PictureBox pic1)
        {
            Rectangle r = new Rectangle(0, 0, pic1.Width, pic1.Height);

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            int d = 24;

            gp.AddArc(r.X, r.Y, d, d, 180, 90);
            gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90);
            gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
            gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90);
            pic1.Region = new Region(gp);
            return(pic1);
        }
Beispiel #34
0
        public Form1(String ime, PocetnaForma pf)
        {
            InitializeComponent();
            igracIme = ime;
            this.igraci = pf.igraci;
            fruits = new List<Fruit>();
            toolStripStatusLabel1.Text = "";
            this.DoubleBuffered = true;
            selected = false;
            pf = new PocetnaForma();
            this.pf = pf;
            i1 = new Igrac(igracIme);

            timer1.Start();
            timer2.Start();

               //za kopceto  da bide okruglo i bez  border
               System.Drawing.Drawing2D.GraphicsPath ag = new System.Drawing.Drawing2D.GraphicsPath();
               ag.AddArc(0, 0, button1.Width, button1.Height, 0, 360);
               button1.Region = new Region(ag);
               button1.TabStop = false;
               button1.FlatStyle = FlatStyle.Flat;
               button1.FlatAppearance.BorderSize = 0;

              //za play kopceto
               System.Drawing.Drawing2D.GraphicsPath ag1 = new System.Drawing.Drawing2D.GraphicsPath();
               ag1.AddArc(0, 0, button2.Width, button2.Height, 0, 360);
               button2.Region = new Region(ag1);
               button2.TabStop = false;
               button2.FlatStyle = FlatStyle.Flat;
               button2.FlatAppearance.BorderSize = 0;
        }
        /// <summary>
        /// Draw curves on graphics with transform and given pen
        /// </summary>
        static void DrawCurves(
            Graphics graphics,
            List<PointF[]> curves,
            System.Drawing.Drawing2D.Matrix transform,
            Pen pen)
        {
            foreach( PointF[] curve in curves )
              {
            System.Drawing.Drawing2D.GraphicsPath gPath = new System.Drawing.Drawing2D.GraphicsPath();
            if( curve.Length == 0 )
            {
              break;
            }
            if( curve.Length == 1 )
            {
              gPath.AddArc( new RectangleF( curve[0], new SizeF( 0.5f, 0.5f ) ), 0.0f, (float) Math.PI );
            }
            else
            {
              gPath.AddLines( curve );
            }
            if( transform != null )
              gPath.Transform( transform );

            graphics.DrawPath( pen, gPath );
              }
        }
        // Zeichnet das Rechteck mit abgerundeten Ecken der Termindetails
        public void DrawRoundRect(Graphics g, Pen p, float x, float y, float width, float height, float radius)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddLine(x + radius, y, x + width - (radius * 2), y); // Line
            gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90); // Corner
            gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2)); // Line
            gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90); // Corner
            gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height); // Line
            gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90); // Corner
            gp.AddLine(x, y + height - (radius * 2), x, y + radius); // Line
            gp.AddArc(x, y, radius * 2, radius * 2, 180, 90); // Corner
            gp.CloseFigure();

            g.DrawPath(p, gp);
            gp.Dispose();
        }
        public static void DrawFrame(System.Drawing.Graphics dc, System.Drawing.RectangleF r, float cornerRadius, System.Drawing.Color color)
        {
            var pen = new System.Drawing.Pen(color);
            if (cornerRadius <= 0)
            {
                dc.DrawRectangle(pen, ColorPickerUtil.Rect(r));
                return;
            }
            cornerRadius = (float)System.Math.Min(cornerRadius, System.Math.Floor(r.Width) - 2);
            cornerRadius = (float)System.Math.Min(cornerRadius, System.Math.Floor(r.Height) - 2);

            var path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddArc(r.X, r.Y, cornerRadius, cornerRadius, 180, 90);
            path.AddArc(r.Right - cornerRadius, r.Y, cornerRadius, cornerRadius, 270, 90);
            path.AddArc(r.Right - cornerRadius, r.Bottom - cornerRadius, cornerRadius, cornerRadius, 0, 90);
            path.AddArc(r.X, r.Bottom - cornerRadius, cornerRadius, cornerRadius, 90, 90);
            path.CloseAllFigures();
            dc.DrawPath(pen, path);
        }
        private System.Drawing.Drawing2D.GraphicsPath RoundRectangle(Rectangle r, int radius, Corners corners)
        {
            //Make sure the Path fits inside the rectangle
            r.Width -= 1;
            r.Height -= 1;

            //Scale the radius if it's too large to fit.
            if (radius > (r.Width))
                radius = r.Width;
            if (radius > (r.Height))
                radius = r.Height;

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

            if (radius <= 0)
                path.AddRectangle(r);
            else
                if ((corners & Corners.TopLeft) == Corners.TopLeft)
                    path.AddArc(r.Left, r.Top, radius, radius, 180, 90);
                else
                    path.AddLine(r.Left, r.Top, r.Left, r.Top);

            if ((corners & Corners.TopRight) == Corners.TopRight)
                path.AddArc(r.Right - radius, r.Top, radius, radius, 270, 90);
            else
                path.AddLine(r.Right, r.Top, r.Right, r.Top);

            if ((corners & Corners.BottomRight) == Corners.BottomRight)
                path.AddArc(r.Right - radius, r.Bottom - radius, radius, radius, 0, 90);
            else
                path.AddLine(r.Right, r.Bottom, r.Right, r.Bottom);

            if ((corners & Corners.BottomLeft) == Corners.BottomLeft)
                path.AddArc(r.Left, r.Bottom - radius, radius, radius, 90, 90);
            else
                path.AddLine(r.Left, r.Bottom, r.Left, r.Bottom);

            path.CloseFigure();

            return path;
        }
        static System.Drawing.Drawing2D.GraphicsPath ResolveGraphicsPath(GraphicsPath path)
        {
            //convert from graphics path to internal presentation
            System.Drawing.Drawing2D.GraphicsPath innerPath = path.InnerPath as System.Drawing.Drawing2D.GraphicsPath;
            if (innerPath != null)
            {
                return innerPath;
            }
            //--------
            innerPath = new System.Drawing.Drawing2D.GraphicsPath();
            path.InnerPath = innerPath;
            List<float> points;
            List<PathCommand> cmds;
            GraphicsPath.GetPathData(path, out points, out cmds);
            int j = cmds.Count;
            int p_index = 0;
            for (int i = 0; i < j; ++i)
            {
                PathCommand cmd = cmds[i];
                switch (cmd)
                {
                    default:
                        throw new NotSupportedException();
                    case PathCommand.Arc:
                        innerPath.AddArc(
                            points[p_index],
                            points[p_index + 1],
                            points[p_index + 2],
                            points[p_index + 3],
                            points[p_index + 4],
                            points[p_index + 5]);
                        p_index += 6;
                        break;
                    case PathCommand.Bezier:
                        innerPath.AddBezier(
                            points[p_index],
                            points[p_index + 1],
                            points[p_index + 2],
                            points[p_index + 3],
                            points[p_index + 4],
                            points[p_index + 5],
                            points[p_index + 6],
                            points[p_index + 7]);
                        p_index += 8;
                        break;
                    case PathCommand.CloseFigure:
                        innerPath.CloseFigure();
                        break;
                    case PathCommand.Ellipse:
                        innerPath.AddEllipse(
                            points[p_index],
                            points[p_index + 1],
                            points[p_index + 2],
                            points[p_index + 3]);
                        p_index += 4;
                        break;
                    case PathCommand.Line:
                        innerPath.AddLine(
                            points[p_index],
                            points[p_index + 1],
                            points[p_index + 2],
                            points[p_index + 3]);
                        p_index += 4;
                        break;
                    case PathCommand.Rect:
                        innerPath.AddRectangle(
                           new System.Drawing.RectangleF(
                          points[p_index],
                          points[p_index + 1],
                          points[p_index + 2],
                          points[p_index + 3]));
                        p_index += 4;
                        break;
                    case PathCommand.StartFigure:
                        break;
                }
            }


            return innerPath;
        }
		/// <summary>
		/// Converts this structure to a GraphicsPath object, used to draw to a Graphics device.
		/// Consider that you can create a Region with a GraphicsPath object using one of the Region constructor.
		/// </summary>
		/// <returns></returns>
		public System.Drawing.Drawing2D.GraphicsPath ToGraphicsPath()
		{
			if (mRectangle.IsEmpty)
				return new System.Drawing.Drawing2D.GraphicsPath();

			System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

			if (mRoundValue == 0)
			{
				//Remove 1 from height and width to draw the border in the right location
				//path.AddRectangle(new Rectangle(new Point(mRectangle.X - 1, mRectangle.Y - 1), mRectangle.Size));
				path.AddRectangle(mRectangle);
			}
			else
			{
				int x = mRectangle.X;
				int y = mRectangle.Y;

				int lineShift = 0;
                int lineShiftX2 = 0;

                //Basically the RoundValue is a percentage of the line to curve, so I simply multiply it with the lower side (height or width)

				if (mRectangle.Height < mRectangle.Width)
				{
                    lineShift = (int)((double)mRectangle.Height * mRoundValue);
                    lineShiftX2 = lineShift * 2;
				}
				else
				{
                    lineShift = (int)((double)mRectangle.Width * mRoundValue);
                    lineShiftX2 = lineShift * 2;
				}

				//Top
                path.AddLine(lineShift + x, 0 + y, (mRectangle.Width - lineShift) + x, 0 + y);
				//Angle Top Right
                path.AddArc((mRectangle.Width - lineShiftX2) + x, 0 + y,
                    lineShiftX2, lineShiftX2, 
					270, 90);
				//Right
                path.AddLine(mRectangle.Width + x, lineShift + y, mRectangle.Width + x, (mRectangle.Height - lineShift) + y);
				//Angle Bottom Right
                path.AddArc((mRectangle.Width - lineShiftX2) + x, (mRectangle.Height - lineShiftX2) + y,
                    lineShiftX2, lineShiftX2, 
					0, 90);
				//Bottom
                path.AddLine((mRectangle.Width - lineShift) + x, mRectangle.Height + y, lineShift + x, mRectangle.Height + y);
				//Angle Bottom Left
                path.AddArc(0 + x, (mRectangle.Height - lineShiftX2) + y,
                    lineShiftX2, lineShiftX2, 
					90, 90);
				//Left
                path.AddLine(0 + x, (mRectangle.Height - lineShift) + y, 0 + x, lineShift + y);
				//Angle Top Left
				path.AddArc(0 + x, 0 + y,
                    lineShiftX2, lineShiftX2, 
					180, 90);
			}

			return path;
		}
Beispiel #41
0
        private System.Drawing.Drawing2D.GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
        {
            int diameter = radius;
            Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

            // 左上角
            path.AddArc(arcRect, 180, 90);

            // 右上角
            arcRect.X = rect.Right - diameter;
            path.AddArc(arcRect, 270, 90);

            // 右下角
            arcRect.Y = rect.Bottom - diameter;
            path.AddArc(arcRect, 0, 90);

            // 左下角
            arcRect.X = rect.Left;
            path.AddArc(arcRect, 90, 90);
            path.CloseFigure();//闭合曲线
            return path;
        }
        /// <summary>
        /// Draws a segment filled.
        /// </summary>
        public void DrawFilled(C2DSegment Segment, Graphics graphics, Brush brush)
        {
            C2DRect Rect = new C2DRect();
            int nStartAngle = 0;
            int nSweepAngle = 0;

            GetArcParameters(Segment.Arc, Rect, ref nStartAngle, ref nSweepAngle);

            if (nSweepAngle == 0)
                nSweepAngle = 1;

            int Width = (int)Rect.Width();
            if (Width == 0)
                Width = 1;
            int Height = (int)Rect.Height();
            if (Height == 0)
                Height = 1;

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddArc((int)Rect.TopLeft.x, (int)Rect.BottomRight.y,
                Width, Height, nStartAngle, nSweepAngle);

            C2DPoint ptFrom = Segment.Arc.Line.GetPointFrom();
            C2DPoint ptTo = Segment.Arc.Line.GetPointTo();
            ScaleAndOffSet(ptFrom);
            ScaleAndOffSet(ptTo);
            gp.AddLine((int)ptTo.x, (int)ptTo.y, (int)ptFrom.x, (int)ptFrom.y);

            graphics.FillPath(brush, gp);
        }
        /// <summary>
        /// Creates a rounded corner rectangle from a regular rectangel
        /// </summary>
        /// <param name="baseRect"></param>
        /// <param name="radius"></param>
        /// <returns></returns>
        private System.Drawing.Drawing2D.GraphicsPath GetRoundedRect(RectangleF baseRect, float radius)
        {
            if ((radius <= 0.0F) || radius >= ((Math.Min(baseRect.Width, baseRect.Height)) / 2.0))
            {
                System.Drawing.Drawing2D.GraphicsPath mPath = new System.Drawing.Drawing2D.GraphicsPath();
                mPath.AddRectangle(baseRect);
                mPath.CloseFigure();
                return mPath;
            }

            float diameter = radius * 2.0F;
            SizeF sizeF = new SizeF(diameter, diameter);
            RectangleF arc = new RectangleF(baseRect.Location, sizeF);
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

            // top left arc 
            path.AddArc(arc, 180, 90);

            // top right arc 
            arc.X = baseRect.Right - diameter;
            path.AddArc(arc, 270, 90);

            // bottom right arc 
            arc.Y = baseRect.Bottom - diameter;
            path.AddArc(arc, 0, 90);

            // bottom left arc
            arc.X = baseRect.Left;
            path.AddArc(arc, 90, 90);

            path.CloseFigure();
            return path;
        }
Beispiel #44
0
		protected System.Drawing.Drawing2D.GraphicsPath GetPath()
		{
			System.Drawing.Drawing2D.GraphicsPath graphPath = new System.Drawing.Drawing2D.GraphicsPath();
			if (this._BorderStyle == System.Windows.Forms.BorderStyle.Fixed3D) 
			{
				graphPath.AddRectangle(this.ClientRectangle);
			} 
			else 
			{
				try 
				{
					int curve = 0;
					System.Drawing.Rectangle rect = this.ClientRectangle;
					int offset = 0;
					if (this._BorderStyle == System.Windows.Forms.BorderStyle.FixedSingle) 
					{
						if (this._BorderWidth > 1) 
						{
							offset = DoubleToInt(this.BorderWidth / 2);
						}
						curve = this.adjustedCurve;
					} 
					else if (this._BorderStyle == System.Windows.Forms.BorderStyle.Fixed3D) 
					{
					} 
					else if (this._BorderStyle == System.Windows.Forms.BorderStyle.None) 
					{
						curve = this.adjustedCurve;
					}
					if (curve == 0) 
					{
						graphPath.AddRectangle(System.Drawing.Rectangle.Inflate(rect, -offset, -offset));
					} 
					else 
					{
						int rectWidth = rect.Width - 1 - offset;
						int rectHeight = rect.Height - 1 - offset;
						int curveWidth = 1;
						if ((this._CurveMode & CornerCurveMode.TopRight) != 0) 
						{
							curveWidth = (curve * 2);
						} 
						else 
						{
							curveWidth = 1;
						}
						graphPath.AddArc(rectWidth - curveWidth, offset, curveWidth, curveWidth, 270, 90);
						if ((this._CurveMode & CornerCurveMode.BottomRight) != 0) 
						{
							curveWidth = (curve * 2);
						} 
						else 
						{
							curveWidth = 1;
						}
						graphPath.AddArc(rectWidth - curveWidth, rectHeight - curveWidth, curveWidth, curveWidth, 0, 90);
						if ((this._CurveMode & CornerCurveMode.BottomLeft) != 0) 
						{
							curveWidth = (curve * 2);
						} 
						else 
						{
							curveWidth = 1;
						}
						graphPath.AddArc(offset, rectHeight - curveWidth, curveWidth, curveWidth, 90, 90);
						if ((this._CurveMode & CornerCurveMode.TopLeft) != 0) 
						{
							curveWidth = (curve * 2);
						} 
						else 
						{
							curveWidth = 1;
						}
						graphPath.AddArc(offset, offset, curveWidth, curveWidth, 180, 90);
						graphPath.CloseFigure();
					}
				} 
				catch (System.Exception) 
				{
					graphPath.AddRectangle(this.ClientRectangle);
				}
			}
			return graphPath;
		}
        /// <summary>
        /// Creates a path based on a polygon.
        /// </summary>
        private System.Drawing.Drawing2D.GraphicsPath CreatePath( C2DPolyBase Poly)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            if (Poly.Lines.Count == 0)
                return gp;

            for (int i = 0; i < Poly.Lines.Count; i++)
            {
                if (Poly.Lines[i] is C2DLine)
                {
                    C2DPoint ptFrom = Poly.Lines[i].GetPointFrom();
                    C2DPoint ptTo = Poly.Lines[i].GetPointTo();
                    ScaleAndOffSet(ptFrom);
                    ScaleAndOffSet(ptTo);
                    gp.AddLine((int)ptFrom.x, (int)ptFrom.y, (int)ptTo.x, (int)ptTo.y);
                }
                else if (Poly.Lines[i] is C2DArc)
                {

                    C2DRect Rect = new C2DRect();
                    int nStartAngle = 0;
                    int nSweepAngle = 0;

                    GetArcParameters(Poly.Lines[i] as C2DArc, Rect, ref nStartAngle, ref nSweepAngle);

                    if (nSweepAngle == 0)
                        nSweepAngle = 1;

                    int Width = (int)Rect.Width();
                    if (Width == 0)
                        Width = 1;
                    int Height = (int)Rect.Height();
                    if (Height == 0)
                        Height = 1;

                    gp.AddArc((int)Rect.TopLeft.x, (int)Rect.BottomRight.y,
                        Width, Height, nStartAngle, nSweepAngle);

                }
            }

            gp.CloseFigure();

            return gp;
        }
Beispiel #46
0
        public static void DrawRoundedRectangle(Graphics gfx, Rectangle Bounds, int CornerRadius, Pen DrawPen, Color FillColor)
        {
            System.Drawing.Drawing2D.GraphicsPath gfxPath = new System.Drawing.Drawing2D.GraphicsPath();

            DrawPen.EndCap = DrawPen.StartCap = System.Drawing.Drawing2D.LineCap.Round;

            gfxPath.AddArc(Bounds.X, Bounds.Y, CornerRadius, CornerRadius, 180, 90);
            gfxPath.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y, CornerRadius, CornerRadius, 270, 90);
            gfxPath.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90);
            gfxPath.AddArc(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90);
            gfxPath.AddLine(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, Bounds.X, Bounds.Y + CornerRadius / 2);

            gfx.FillPath(new SolidBrush(FillColor), gfxPath);
            gfx.DrawPath(DrawPen, gfxPath);
        }
Beispiel #47
0
 /// <summary>
 /// Creates a GraphicsPath object and adds an arc to it with the specified arc values and closure type.
 /// </summary>
 /// <param name="x">The x coordinate of the upper-left corner of the rectangular region that defines the ellipse from which the arc is drawn.</param>
 /// <param name="y">The y coordinate of the upper-left corner of the rectangular region that defines the ellipse from which the arc is drawn.</param>
 /// <param name="height">The height of the rectangular region that defines the ellipse from which the arc is drawn.</param>
 /// <param name="width">The width of the rectangular region that defines the ellipse from which the arc is drawn.</param>
 /// <param name="start">The starting angle of the arc measured in degrees.</param>
 /// <param name="extent">The angular extent of the arc measured in degrees.</param>
 /// <param name="arcType">The closure type for the arc.</param>
 /// <returns>Returns a new GraphicsPath object that contains the arc path.</returns>
 public static System.Drawing.Drawing2D.GraphicsPath CreateArc2D(float x, float y, float height, float width, float start, float extent, int arcType)
 {
     System.Drawing.Drawing2D.GraphicsPath arc2DPath = new System.Drawing.Drawing2D.GraphicsPath();
     switch (arcType)
     {
         case OPEN:
             arc2DPath.AddArc(x, y, height, width, start * -1, extent * -1);
             break;
         case CLOSED:
             arc2DPath.AddArc(x, y, height, width, start * -1, extent * -1);
             arc2DPath.CloseFigure();
             break;
         case PIE:
             arc2DPath.AddPie(x, y, height, width, start * -1, extent * -1);
             break;
         default:
             break;
     }
     return arc2DPath;
 }
Beispiel #48
0
        /// <summary>角の丸い矩形のGraphicsPathを生成する</summary>
        public static System.Drawing.Drawing2D.GraphicsPath CreateRoundedGraphicsPath(RectangleF bounds, float xRadius, float yRadius) {
            float left = bounds.X;
            float top = bounds.Y;
            float right = bounds.Right;
            float bottom = bounds.Bottom;

            var path = new System.Drawing.Drawing2D.GraphicsPath();
            path.StartFigure();
            path.AddArc(left, top, xRadius * 2, yRadius * 2, 180, 90);
            path.AddArc(right - xRadius * 2, top, xRadius * 2, yRadius * 2, 270, 90);
            path.AddArc(right - xRadius * 2, bottom - yRadius * 2, xRadius * 2, yRadius * 2, 0, 90);
            path.AddArc(left, bottom - yRadius * 2, xRadius * 2, xRadius * 2, 90, 90);
            path.CloseFigure();

            return path;
        }
        /// <summary>
        /// Fill a closed path composed of several drawing operations
        /// </summary>
        /// <param name="canvas"></param>
        public void Fill(System.Drawing.Graphics canvas)
        {
            System.Drawing.Drawing2D.GraphicsPath path;

            path = new System.Drawing.Drawing2D.GraphicsPath();
            for (int i = 0; i < m_drawings.Count; i++)
            {
                switch (m_drawings[i].Type)
                {
                    case DrawingType.Line:
                    {
                        path.AddLine(m_drawings[i].Points[0].x, m_drawings[i].Points[0].y, m_drawings[i].Points[1].x, m_drawings[i].Points[1].y);
                        break;
                    }
                    case DrawingType.Arc:
                    {
                        double	startAngle, endAngle;

                        startAngle = System.Math.Atan2(m_drawings[i].Points[2].y - (m_drawings[i].Points[1].y + m_drawings[i].Points[0].y) / 2, m_drawings[i].Points[2].x - (m_drawings[i].Points[1].x + m_drawings[i].Points[0].x) / 2);
                        if (startAngle < 0)
                        {
                            startAngle += System.Math.PI * 2;
                        }
                        startAngle = (startAngle / Math.PI) * 180;

                        endAngle = System.Math.Atan2(m_drawings[i].Points[3].y - (m_drawings[i].Points[1].y + m_drawings[i].Points[0].y) / 2, m_drawings[i].Points[3].x - (m_drawings[i].Points[1].x + m_drawings[i].Points[0].x) / 2);
                        if (endAngle < 0)
                        {
                            endAngle += System.Math.PI * 2;
                        }
                        endAngle = (endAngle / Math.PI) * 180;

                        path.AddArc(m_drawings[i].Points[0].x, m_drawings[i].Points[0].y, m_drawings[i].Points[1].x - m_drawings[i].Points[0].x, m_drawings[i].Points[1].y - m_drawings[i].Points[0].y, (float)startAngle, Math.Abs((float)(endAngle - startAngle)));
                        break;
                    }
                    case DrawingType.Bezier:
                    {
                        path.AddBezier(m_drawings[i].Points[0].x, m_drawings[i].Points[0].y, m_drawings[i].Points[2].x, m_drawings[i].Points[2].y, m_drawings[i].Points[3].x, m_drawings[i].Points[3].y, m_drawings[i].Points[1].x, m_drawings[i].Points[1].y);
                        break;
                    }
                }
            }

            canvas.FillPath(m_style.fillingStyle, path);
        }
Beispiel #50
0
 public static void DrawRoundedRectangleOutlined(Graphics gfxObj, Pen penObj, float X, float Y, float RectWidth, float RectHeight, float CornerRadius)
 {
     RectWidth--;
     RectHeight--;
     System.Drawing.Drawing2D.GraphicsPath gfxPath = new System.Drawing.Drawing2D.GraphicsPath();
     gfxPath.AddLine(X + CornerRadius, Y, X + RectWidth - (CornerRadius * 2), Y);
     gfxPath.AddArc(X + RectWidth - (CornerRadius * 2), Y, CornerRadius * 2, CornerRadius * 2, 270, 90);
     gfxPath.AddLine(X + RectWidth, Y + CornerRadius, X + RectWidth, Y + RectHeight - (CornerRadius * 2));
     gfxPath.AddArc(X + RectWidth - (CornerRadius * 2), Y + RectHeight - (CornerRadius * 2), CornerRadius * 2, CornerRadius * 2, 0, 90);
     gfxPath.AddLine(X + RectWidth - (CornerRadius * 2), Y + RectHeight, X + CornerRadius, Y + RectHeight);
     gfxPath.AddArc(X, Y + RectHeight - (CornerRadius * 2), CornerRadius * 2, CornerRadius * 2, 90, 90);
     gfxPath.AddLine(X, Y + RectHeight - (CornerRadius * 2), X, Y + CornerRadius);
     gfxPath.AddArc(X, Y, CornerRadius * 2, CornerRadius * 2, 180, 90);
     gfxPath.CloseFigure();
     gfxObj.DrawPath(penObj, gfxPath);
     gfxPath.Dispose();
 }
Beispiel #51
0
 private void DrawRoundRect(Graphics g, float x, float y, float width, float height, float radius, Color color)
 {
     System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
     gp.AddLine(x + radius, y, x + width - (radius * 2), y); //追加线段
     gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90);  //追加椭圆弧
     gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2));
     gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90);
     gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height);
     gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
     gp.AddLine(x, y + height - (radius * 2), x, y + radius);
     gp.AddArc(x, y, radius * 2, radius * 2, 180, 90);
     gp.CloseFigure();
     Pen pen = new System.Drawing.Pen(ColorTranslator.FromHtml("#CCCCCC"), 1);
     g.DrawPath(pen, gp);
     Rectangle rec = new Rectangle((int)x, (int)y, (int)width, (int)height);
     Brush brush = new System.Drawing.SolidBrush(color);
     g.FillPath(brush, gp);
     gp.Dispose();
 }
Beispiel #52
0
            /// <summary>
            /// Creates a GraphicsPath object and adds an arc to it with the specified arc values and closure type.
            /// </summary>
            /// <param name="ellipseBounds">A RectangleF structure that represents the rectangular bounds of the ellipse from which the arc is taken.</param>
            /// <param name="start">The starting angle of the arc measured in degrees.</param>
            /// <param name="extent">The angular extent of the arc measured in degrees.</param>
            /// <param name="arcType">The closure type for the arc.</param>
            /// <returns>Returns a new GraphicsPath object that contains the arc path.</returns>
            public static System.Drawing.Drawing2D.GraphicsPath CreateArc2D(System.Drawing.RectangleF ellipseBounds, float start, float extent, int arcType)
            {
                System.Drawing.Drawing2D.GraphicsPath arc2DPath = new System.Drawing.Drawing2D.GraphicsPath();
                switch (arcType)
                {
                    case OPEN:
                        arc2DPath.AddArc(ellipseBounds, start * -1, extent * -1);
                        break;
                    case CLOSED:
                        arc2DPath.AddArc(ellipseBounds, start * -1, extent * -1);
                        arc2DPath.CloseFigure();
                        break;
                    case PIE:
                        arc2DPath.AddPie(ellipseBounds.X, ellipseBounds.Y, ellipseBounds.Width, ellipseBounds.Height, start * -1, extent * -1);
                        break;
                    default:
                        break;
                }

                return arc2DPath;
            }