私は自分の comp103 ペーパーの改訂を行っていますが、Graphics.Clear(); でボタンを取得できません。グラフィックペーパーをクリアする方法。ネットで答えを見つけるのに約1時間費やしたので、誰かが私のコードのエラーを指摘してください。
このような初心者の質問をして申し訳ありません。
コードは次のとおりです。
namespace Week_4_Ex1
{
public partial class Form1 : Form
{
const int height1 = 150; // A constant that stores the flags height
const int width1 = 100; // A constant that stores the flags width
public Form1()
{
InitializeComponent();
}
/// <summary>
/// Button event that Draws a flag
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDraw_Click(object sender, EventArgs e)
{
Graphics Paper = this.CreateGraphics(); // Creates graphics paper to draw on
Brush br1 = new SolidBrush(Color.Blue); // Creates a blue brush to draw with
Brush br2 = new SolidBrush (Color.Orange); // Creates a orange brush to draw with
Brush br3 = new SolidBrush (Color.Red); // Creates a red brush to draw with
Pen Pen1 = new Pen(Color.Blue); // Creates a blue pen to draw with
Pen Pen2 = new Pen(Color.Orange); // Creates a orange pen to draw with
Pen Pen3 = new Pen(Color.Red); // Creates a red pen to draw with
//The following code draws a flag
Paper.DrawRectangle(Pen1, 10, 10, width1, height1); // Draws a blue rectangle
Paper.FillRectangle(br1, 10, 10, width1, height1); // Fills the rectangle with blue
Paper.DrawRectangle(Pen2, 110, 10, width1, height1); // Draws a blue rectangle
Paper.FillRectangle(br2, 110, 10, width1, height1); // Fills the rectangle with blue
Paper.DrawRectangle(Pen3, 210, 10, width1, height1); // Draws a blue rectangle
Paper.FillRectangle(br3, 210, 10, width1, height1); // Fills the rectangle with blue
}
/// <summary>
/// Button that closes the form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnExit_Click(object sender, EventArgs e)
{
this.Close(); // Closes the form
}
/// <summary>
/// Clears the picturebox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnErase_Click(object sender, EventArgs e)
{
Graphics.Clear(); //**THIS DOESN'T WORK**
}
}
}
乾杯、ラブ