“用户在图片框中”绘制的图像上的“撤消”和“重做”行 [英] Undo and Redo Lines on the image drawn by User in Picture Box

查看:92
本文介绍了“用户在图片框中”绘制的图像上的“撤消”和“重做”行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!每个人!

我正在写一个应用程序:从PC加载照片然后显示在图片框上,即:

 当用户按下F1时,将在鼠标坐标指向的图片上绘制一条线。我的问题是当用户再次按下F1时,最初会删除该行,而是在新位置绘制新行。

我也提到一些链接,但没有解决方案。我们希望所有的建议和帮助,以便我可以完成我的项目。

一个链接有参考编号:

1. http://social.msdn.microsoft.com/Forums/windows/en-US/4dd351f7-f37f- 45d9-8c34-50c1b52b27df /撤消和 - 重做线 - 上的图像绘制通过用户中画-箱的-CSHARP - 窗口形式?论坛= WinForms的 [<一个HREF =http://social.msdn.microsoft.com/Forums/windows/en-US/4dd351f7-f37f-45d9-8c34-50c1b52b27df/undo-and-redo-lines-on-the-image-drawn-by -user-in-picture-of-csharp-windows-form?forum = winformstarget =_ blanktitle =New Window> ^ ]

谢谢大家非常

Hi! Every body!
I'm writing an application: Load photos from PC then displayed on the picturebox, namely:
  When the user presses F1, a line will be drawn up at the picture that the mouse coordinates are pointing to. My problem is when the user presses F1 again, the line will be drawn initially deleted instead new line will be drawn at the new location.
I also refer to some links but no solutions. We wish all the suggestions and help so that I can complete my project.
A link has reference number:
1. http://social.msdn.microsoft.com/Forums/windows/en-US/4dd351f7-f37f-45d9-8c34-50c1b52b27df/undo-and-redo-lines-on-the-image-drawn-by-user-in-picture-box-of-csharp-windows-form?forum=winforms[^]
Thank you all very much

推荐答案

嗨BillWoodruf F!感谢您的回答。

行是从以下函数中提取的,此函数在表单的keydown事件中调用。

Hi BillWoodruff! Thanks for your answer.
Line is drawn from the following functions, this function is called in the keydown event of the form.
public void DrawLine(PictureBox pb, Point p, Color color)
        {
            try
            {
                Point p1 = new Point();
                Point p2 = new Point();
                Point p3 = new Point();
                Point p4 = new Point();
                //Draw as plus sign
                p1.X = p.X;
                p1.Y = p.Y - 10;
                p2.X = p.X;
                p2.Y = p.Y + 10;
                p3.X = p.X - 10;
                p3.Y = p.Y;
                p4.X = p.X + 10;
                p4.Y = p.Y;
                pb.Refresh();
                Bitmap bmp = (Bitmap)pb.Image;
                Graphics g = Graphics.FromImage(bmp);
                Pen pe = new Pen(color, 3);
                g.DrawLine(pe, p1, p2);
                g.DrawLine(pe, p3, p4);
                pb.Image = bmp;
                pe.Dispose();
                g.Dispose();
            }
            catch
            {
                MessageBox.Show("Please select image let draw!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }



当用户绘制一条新线时,之前已经删除了该线。


And when the user draw a new line, the line has been drawn previously been removed.


这篇关于“用户在图片框中”绘制的图像上的“撤消”和“重做”行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆