[英]loading an image,drawing shapes on it by clicking a button,drawing lines on it by mouse
I want to load an image (for example in a panel) and messure the edges of the picture_by using the functions I have_ and draw the lines of the edges on the image by clicking a button.After that, I want to draw extra lines on the same image by using mouse.I also want to be able to erase the painted lines by mouse without erasing the image later. 我想加载图像(例如在面板中)并使用我拥有的功能弄乱picture_的边缘,然后单击按钮在图像上绘制边缘的线。之后,我想在其上绘制多余的线我还希望能够用鼠标擦除绘制的线条而不会在以后删除图像。 I don't know which function I should use in every case.One way may be that I set the backgroundImage of the panel with my image and use the paint function to draw exta lines _drawn by mouse.if I use this method, then which function should I use to draw lines of edges_drawn by clicking button?
我不知道在每种情况下都应该使用哪个函数。一种方法可能是我用图像设置面板的backgroundImage并使用paint函数绘制用鼠标绘制的_线条。我应该通过单击按钮来绘制edge_drawed线吗? Is there a better way?
有没有更好的办法? Please guide me .Thanks in advance.
请指导我。谢谢。
see below code ..hope this will help you 看到下面的代码..希望这将帮助您
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.