我已经if语句在我的代码如下:这为什么不画任何东西?
//global variables
int x1;
int y1;
int x2;
int y2;
int counter = 0;
private void pictureBox1_Click(object sender, EventArgs e)
{
if (radioButtonDrawLine.Checked)
{
if (counter == 0)
{
x1 = Cursor.Position.X;
y1 = Cursor.Position.Y;
counter++;
}
else
{
x2 = Cursor.Position.X;
y2 = Cursor.Position.Y;
if (counter == 1)
{
Graphics g = CreateGraphics();
g.DrawLine(Pens.Black, x2, y2, x1, y1);
}
counter = 0;
}
}
}
我应该在我的PictureBox点击两次,并将其保存在x和y每次我点击。在第二次点击时,应在两个坐标之间绘制一条线。 虽然这并不工作,我不明白为什么。有人能告诉我什么是错的吗?
'radioButtonDrawLine.Checked == true?' –
仍然不起作用。我认为它应该是相同的,而不使用“== true” –