【发布时间】:2017-07-12 03:56:24
【问题描述】:
我的代码中有以下 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;
}
}
}
我应该在我的图片框上单击两次,每次单击时它都会保存 x 和 y。在第二次单击时,应在两个坐标之间绘制一条线。 但是这不起作用,我不知道为什么。谁能告诉我怎么了?
【问题讨论】:
-
radioButtonDrawLine.Checked == true? -
还是不行。我认为不使用“== true”应该是一样的
标签: c# winforms system.drawing