2012-03-29 6 views
0

以下のように、コードで楕円を描きます。どのように赤い色の高さを楕円の内側にすることができますかは、例えば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); 
    } 

答えて

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

私が試したし、成功してきましたが、先生ありがとうを:) – yd4

関連する問題