当前位置: 首页>>代码示例>>C#>>正文


C# GraphicsPath.AddPolygon方法代码示例

本文整理汇总了C#中GraphicsPath.AddPolygon方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicsPath.AddPolygon方法的具体用法?C# GraphicsPath.AddPolygon怎么用?C# GraphicsPath.AddPolygon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GraphicsPath的用法示例。


在下文中一共展示了GraphicsPath.AddPolygon方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnPaint

    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        int intRate = 0;
        e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        Color UseFillColor = new Color();
        Color UseBorderColor = new Color();
        GraphicsPath ShapePath = new GraphicsPath();
        float ptx;
        float pty;
        StringFormat sf = new StringFormat();
        sf.Alignment = StringAlignment.Center;
        sf.LineAlignment = StringAlignment.Center;

        pty = (this.Height - (RadiusOuter * 2)) / 2;
        intRate = 0;
        while (!(intRate == MaxRating))
        {
          ptx = intRate * (RadiusOuter * 2 + ShapeGap) + Padding.Left + (ShapeGap / 2);
          if (PaintRating > intRate)
          {
        if (!IsPainting & HighlightRateFill & (PaintRating != intRate + 1))
        {
          UseFillColor = ShapeColorHover;
          UseBorderColor = ShapeBorderHoverColor;
        }
        else if (IsPainting & HighlightRateHover & (PaintRating == intRate + 1))
        {
          UseFillColor = ShapeColorFill;
          UseBorderColor = ShapeBorderFilledColor;
        }
        else
        {
          UseFillColor = PaintColor;
          UseBorderColor = PaintBorderColor;
        }
          }
          else
          {
        UseFillColor = ShapeColorEmpty;
        UseBorderColor = ShapeBorderEmptyColor;
          }

          ShapePath.Reset();
          Point[] pts;
          switch (Shape)
          {
        case eShape.Star:
          ShapePath = DrawStar(ptx, pty);
          break;
        case eShape.Heart:
          ShapePath = DrawHeart(ptx, pty);
          break;
        case eShape.Square:
          ShapePath.AddRectangle(new Rectangle((int)ptx, (int)pty, (int)(RadiusOuter * 2), (int)(RadiusOuter * 2)));
          break;
        case eShape.Circle:
          ShapePath.AddEllipse(ptx, pty, RadiusOuter * 2, RadiusOuter * 2);
          break;
        case eShape.Diamond:
          pts = new Point[] { new Point((int)(ptx + RadiusOuter), (int)pty), new Point((int)(ptx + RadiusOuter * 2), (int)(pty + RadiusOuter)), new Point((int)(ptx + RadiusOuter), (int)(pty + RadiusOuter * 2)), new Point((int)ptx, (int)(pty + RadiusOuter)) };
          ShapePath.AddPolygon(pts);
          break;
        case eShape.Triangle:
          pts = new Point[] { new Point((int)(ptx + RadiusOuter), (int)pty), new Point((int)(ptx + RadiusOuter * 2), (int)(pty + RadiusOuter * 2)), new Point((int)ptx, (int)(pty + RadiusOuter * 2)) };
          ShapePath.AddPolygon(pts);
          break;

          }

          e.Graphics.FillPath(new SolidBrush(UseFillColor), ShapePath);
          e.Graphics.DrawPath(new Pen(UseBorderColor, ShapeBorderWidth), ShapePath);

          if (ShapeNumberShow != eShapeNumberShow.None)
          {
        if (ShapeNumberShow == eShapeNumberShow.All | (ShapeNumberShow == eShapeNumberShow.RateOnly & PaintRating == intRate + 1))
        {
          e.Graphics.DrawString((intRate + 1).ToString(), ShapeNumberFont, new SolidBrush(ShapeNumberColor), new RectangleF(ShapeNumberIndent.X + ptx, ShapeNumberIndent.Y + pty, RadiusOuter * 2, RadiusOuter * 2), sf);
        }
          }

          intRate += 1;
        }

        if (LabelShow)
        {
          int R_x = (int)(((RadiusOuter * 2) * (MaxRating)) + LabelIndent + ((ShapeGap) * MaxRating) + Padding.Left);
          if (IsPainting)
          {
        RateLabel.Text = GetLabelText(LabelTypeHover);
          }
          else
          {
        RateLabel.Text = GetLabelText(LabelTypeText);
          }
          RateLabel.Width = (this.Width - R_x);
          RateLabel.Height = (this.Height);
          RateLabel.Location = new Point(R_x, 0);
        }
    }
开发者ID:jcbarton,项目名称:MUMS,代码行数:99,代码来源:ShapeRater.cs

示例2: IsFit

    public bool IsFit(Point[] points)
    {
        // Note: rigorously calculating distance(point,ellipse) is very hard...
        // overlay the regions and compare the areas, for now.
        using (GraphicsPath polygp = new GraphicsPath())
        using (GraphicsPath elligp = new GraphicsPath())
        using (Matrix m = new Matrix())
        {
            // Set up gp for stroke.
            polygp.AddPolygon(points);

            // Set up gp for ellipse.
            elligp.AddEllipse((float)-mj,(float)-mn,(float)mj*2,(float)mn*2);

            m.Translate((float)cx,(float)cy);
            m.Rotate((float)th);
            elligp.Transform(m);

            // Prepare regions for area-calculation.
            using (Region xor = new Region(elligp))
            using (Region isc = new Region(elligp))
            {
                xor.Xor(polygp);
                isc.Intersect(polygp);

                float badarea = Geometry.CalculateArea(xor);
                float iscarea = Geometry.CalculateArea(isc);
                float ratio = iscarea/badarea;

                //heuristic: 10.0 seems about right.
                return (ratio > 10f);
            }
        }
    }
开发者ID:pichiliani,项目名称:CoPhysicsSimulator,代码行数:34,代码来源:Ellipse.cs

示例3: DrawStar

    public GraphicsPath DrawStar(float Xc, float Yc)
    {
        GraphicsPath gp = new GraphicsPath();
        Xc += RadiusOuter;
        Yc += RadiusOuter;
        // RadiusInner and InnerRadius: determines how far from the center the inner vertices of the star are.
        // RadiusOuter: determines the size of the star.
        // xc, yc: determine the location of the star.
        float sin36 = (float)Math.Sin(36.0 * Math.PI / 180.0);
        float sin72 = (float)Math.Sin(72.0 * Math.PI / 180.0);
        float cos36 = (float)Math.Cos(36.0 * Math.PI / 180.0);
        float cos72 = (float)Math.Cos(72.0 * Math.PI / 180.0);
        float InnerRadius = (RadiusOuter * cos72 / cos36) + RadiusInner;

        PointF[] pts = new PointF[10];
        pts[0] = new PointF(Xc, Yc - RadiusOuter);
        pts[1] = new PointF(Xc + InnerRadius * sin36, Yc - InnerRadius * cos36);
        pts[2] = new PointF(Xc + RadiusOuter * sin72, Yc - RadiusOuter * cos72);
        pts[3] = new PointF(Xc + InnerRadius * sin72, Yc + InnerRadius * cos72);
        pts[4] = new PointF(Xc + RadiusOuter * sin36, Yc + RadiusOuter * cos36);
        pts[5] = new PointF(Xc, Yc + InnerRadius);
        pts[6] = new PointF(Xc - RadiusOuter * sin36, Yc + RadiusOuter * cos36);
        pts[7] = new PointF(Xc - InnerRadius * sin72, Yc + InnerRadius * cos72);
        pts[8] = new PointF(Xc - RadiusOuter * sin72, Yc - RadiusOuter * cos72);
        pts[9] = new PointF(Xc - InnerRadius * sin36, Yc - InnerRadius * cos36);

        gp.AddPolygon(pts);

        return gp;
    }
开发者ID:jcbarton,项目名称:MUMS,代码行数:30,代码来源:ShapeRater.cs


注:本文中的GraphicsPath.AddPolygon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。