VB - 无法找到撤消图形的方法 [英] VB - Can't find a way to undo graphics

查看:75
本文介绍了VB - 无法找到撤消图形的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


最近,我开始了一个关于图形的项目。好吧,我添加了一个按钮,用于撤消上一个操作。然而,我想到的唯一解决方案是在每个动作之后保存一张新图片,我不想以这种方式撤消。还有其他
撤消方法吗?


当前代码:

 Dim g As graphics 
Dim r As Random
Dim pen As Pen = New Pen(Color.red)
Private Sub Form1_Load(sender as Object,e as eventArgs)Handles Me.Load
g = me。 createGraphics()
g.drawline(pen,R.Next(1,100),R.Next(1,100),R.Next(1,100),R.Next(1,100))
End Sub
Private Sub Button1_Click(发送者作为对象,e作为eventArgs)处理Button1.Click
'一些撤消代码
End Sub

解决方案


最近,我开始了关于图形的项目。好吧,我添加了一个按钮,用于撤消上一个操作。然而,我想到的唯一解决方案是在每个动作之后保存一张新图片,我不想以这种方式撤消。还有其他
的撤消方法吗?


用添加行信息的代码替换绘制该行的代码(起点,结束) (点)到可以存储该行信息的对象的集合(例如List)。   然后通过迭代集合在表单的Paint事件处理程序
中进行绘制。  要"撤消"一行,请从列表中删除最后一项,然后刷新图像,以便从头开始再次完成绘图(当然,没有列表中的最后一项)。 请参阅:

https://vbdotnetblog.wordpress.com/graphics/graphics-methodology/





Hey

Lately I started a project on graphics. Well I added a button, for undoing the last action. However the only solution I have figured is to save a new picture after every single action, which I don't really want to undo in this way. Is there any other ways of undoing?

Current code:

Dim g As graphics
Dim r As Random
Dim pen As Pen = New Pen(Color.red)
Private Sub Form1_Load(sender As object, e As eventArgs) Handles Me.Load
g = me.createGraphics()
g.drawline(pen,R.Next(1,100),R.Next(1,100),R.Next(1,100),R.Next(1,100))
End Sub
Private Sub Button1_Click(sender As object, e As eventArgs) Handles Button1.Click
'Some undoing code
End Sub

解决方案

Lately I started a project on graphics. Well I added a button, for undoing the last action. However the only solution I have figured is to save a new picture after every single action, which I don't really want to undo in this way. Is there any other ways of undoing?

Replace the code that draws the line with code that adds the line information (start point, end point) to a collection (such as a List) of objects that can store that line information.   Then do the drawing in the form's Paint event handler by iterating through the collection.   To 'undo' a line, remove the last item from the list, and refresh the image so that the drawing is done again from the beginning (but, of course, without the last item in the list).  See:
https://vbdotnetblog.wordpress.com/graphics/graphics-methodology/


这篇关于VB - 无法找到撤消图形的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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