Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更改椭圆中包含的高度级别_C#_Draw_Drawellipse - Fatal编程技术网

C# 更改椭圆中包含的高度级别

C# 更改椭圆中包含的高度级别,c#,draw,drawellipse,C#,Draw,Drawellipse,我用如下所示的代码绘制椭圆。如何使红色的高度在椭圆内可以改变,例如从0%-100%。如果0%,则表示红色高度级别为空。如果50%,则红色的高度级别为椭圆的一半。如果100%,则红色的高度级别为满。多谢各位 private void panel1_Paint(object sender, PaintEventArgs e) { Rectangle r1= new Rectangle(10, 130, 60, 60); // Create solid

我用如下所示的代码绘制椭圆。如何使红色的高度在椭圆内可以改变,例如从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);
    }

请尝试以下代码:

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();
}