我想加载一个图像(例如在面板中)并使用我拥有的函数弄乱picture_by的边缘,并通过单击按钮在图像上绘制边缘的线条。之后,我想绘制通过使用鼠标在同一图像上的额外线条。我还希望能够通过鼠标擦除绘制的线条,而不会在以后擦除图像。 我不知道在每种情况下我应该使用哪个函数。一种方法可能是我用我的图像设置面板的backgroundImage并使用绘图函数通过鼠标绘制exta线_drawn。如果我使用这个方法,那么我应该使用函数通过单击按钮绘制edges_drawn行?有没有更好的办法?请指导我。谢谢。
答案 0 :(得分:0)
见下面的代码..希望这会对你有帮助
Point startPoint = new Point();
bool dragging = false;
int testOne = 30;
int testTwo = 30;
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (dragging)
{
int diffX = (pictureBox1.PointToClient(e.Location).X - startPoint.X);
int diffY = (pictureBox1.PointToClient(e.Location).Y - startPoint.Y);
label9.Text = diffX.ToString(); //Works, shows desired result
label10.Text = diffY.ToString(); //also works fine
testOne = (testOne + diffX); //Issue here
testTwo = (testTwo + diffY); //and here
label11.Text = (testOne).ToString(); //Unexpected results output
label12.Text = (testTwo).ToString();
}
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (!dragging) //Incase the mouse down was repeating, it's not
{
startPoint = pictureBox1.PointToClient(e.Location);
dragging = true;
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (dragging)
dragging = false;
}