私のcomp103用紙のリビジョンをいくつかしていますが、Graphics.Clear()でボタンを取得できません。メソッドを使用してグラフィックス用紙をクリアします。誰かが私のコードでエラーを指摘してください。私は約1時間インターネット上で答えを見つけようとしました。WhysはGraphics.Clear()です。 C#で動作していない
このような質問には申し訳ありません。ここで
は、コードは次のとおりです。
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**
}
}
}
乾杯、 ラブ
「動作しません」と定義します。 – Tudor
まず、MSDNのクイックビューでは、 'Clear'は' Graphics'型の静的メソッドではなく、さらに 'color'パラメータが必要であることがわかります。 – Tudor
これは実際のコードですか?あなたのクラスはGraphicsメンバを持っておらず、 'Graphics.Clear'メソッドは静的ではありません。 –