System.Drawing.Drawing2D.GraphicsPath.CloseAllFigures C# (CSharp) Method

CloseAllFigures() public method

public CloseAllFigures ( ) : void
return void
        public void CloseAllFigures()
        {
            int index = 0;
            byte currentType;
            byte lastType;
            byte[] oldTypes;

            /* first point is not closed */
            if (points.Count <= 1)
                return;

            oldTypes = types.ToArray();
            types = new List<byte> ();

            lastType = oldTypes[index];
            index++;

            for (index = 1; index < points.Count; index++) {
                currentType = oldTypes [index];
                /* we dont close on the first point */
                if ((currentType == (byte)PathPointType.Start) && (index > 1))
                {
                    lastType |= (byte)PathPointType.CloseSubpath;
                    types.Add (lastType);
                }
                else
                    types.Add(lastType);

                lastType = currentType;
            }

            /* close at the end */
            lastType |= (byte)PathPointType.CloseSubpath;
            types.Add(lastType);

            start_new_fig = true;
        }

Usage Example

Exemplo n.º 1
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));
            }
        }
All Usage Examples Of System.Drawing.Drawing2D.GraphicsPath::CloseAllFigures