我想在我的按钮上绘制一个椭圆,形成应用程序C#

时间:2017-12-06 09:48:48

标签: c# forms

我在按钮上绘制一个圆/椭圆有一些问题,因为我将它们绘制在表单上而不是按钮本身意味着它们最终会被按钮覆盖。

现在我像这样绘制椭圆

   Pen green = new Pen(Color.Green, 1);
   Rectangle rectEllipse = new Rectangle(100, 40, 30, 30);
   e.Graphics.DrawEllipse(black, rectEllipse);

1 个答案:

答案 0 :(得分:2)

您必须使用Button,而不是Form

private void myButton_Paint(object sender, PaintEventArgs e) {
  //DONE: wrap IDisposable into using 
  using (Pen green = new Pen(Color.Green, 1)) {
    Rectangle rectEllipse = new Rectangle(10, 10, 30, 30);
    // typo? You, probably, mean "green", not "black"
    e.Graphics.DrawEllipse(green, rectEllipse); 
  }
}