【问题标题】:Change the height level contained in the ellipse更改椭圆中包含的高度级别
【发布时间】:2012-04-13 05:57:37
【问题描述】:

我用如下所示的代码绘制椭圆。如何使红色的高度在椭圆内可以更改,例如从 0% -100%。如果为 0%,则表示红色高度的级别为空。如果 50% 表示红色的高度水平是椭圆的一半。如果 100% 表示红色的高度级别是满的。谢谢。

    private void panel1_Paint(object sender, PaintEventArgs e)
    {
        Rectangle r1= new Rectangle(10, 130, 60, 60);

        // Create solid brush.
        SolidBrush redBrush = new SolidBrush(Color.Red);

        // Create location and size of ellipse.
        float x = 20F;
        float y = 20F;
        float width = 80.0F;
        float height = 200.0F;

        // Fill ellipse on screen.
        e.Graphics.FillEllipse(redBrush, x, y, width, height);
    }

【问题讨论】:

    标签: c# draw drawellipse


    【解决方案1】:

    请尝试以下代码:

    void panel1_Paint(object sender, PaintEventArgs e)
        float percent = 0.75f;
        RectangleF bounds = new RectangleF(20, 20, 80, 200);
        FillEllipse(e.Graphics, bounds, percent);
    }
    static void FillEllipse(Graphics g, RectangleF bounds, float percent) {
        g.DrawEllipse(Pens.Red, bounds);
        g.SetClip(new RectangleF(
            bounds.X,
            bounds.Y + (1f - percent) * bounds.Height,
            bounds.Width,
            percent * bounds.Height));
    
        g.FillEllipse(Brushes.Red, bounds);
        g.ResetClip();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-15
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多