WPF:如何删除画布中的某些内容? [英] WPF: How to Erase somthing in canvas?

查看:137
本文介绍了WPF:如何删除画布中的某些内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试制作绘图板支持添加形状和图像。对于铅笔我使用此代码我不认为有办法擦除它但只是尝试

Hello, I''m trying to make a drawing board tha support adding shapes and images. for pencil I use this code and I don''t think that there is a way to erase it but just trying:

            Dim lin As New Line
            lin.Stroke = New SolidColorBrush(Color.FromArgb(100, 255, 0, 0))
            lin.StrokeThickness = 5
'lastpnt is the LastPoint added to continue the drawing and it will be null on mouse_up Event
            If Not lastpnt = Nothing Then
                lin.X1 = lastpnt.X
                lin.Y1 = lastpnt.Y
                lin.X2 = position.X
                lin.Y2 = position.Y
                lastpnt.X = position.X
                lastpnt.Y = position.Y
            Else
                lin.X1 = position.X
                lin.Y1 = position.Y
                lin.X2 = position.X
                lin.Y2 = position.Y
                lastpnt.X = position.X
                lastpnt.Y = position.Y
            End If
            Canvas1.Children.Add(lin)





我可以使橡皮擦与背景颜色相同,但如果背面颜色是透明或是图像 ????

我现在将阅读''$ code> InkCanvas ''源代码,试图找到另一种绘制和擦除方式。



注意:我没有使用inkcanvas du e不支持在绘图上方添加图像然后在图像上绘图(我不知道如何解释,但它像墨水和图像zOrder)



I can make the eraser the same as background color but what if the back color was transparent or was an image ????
I will now read the ''InkCanvas'' source code trying to find another way to draw and erase.

Note : I didn''t use inkcanvas due to no support adding images above the ink drawing and then drawing on image (I don''t know how to explain but its like ink and Images zOrder)

推荐答案

以下是: Canvas 是UIElements集合的父元素,可作为属性 Children

http:// msdn .microsoft.com / zh-cn / library / system.windows.controls.panel.children.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.controls.uielementcollection.aspx [< a href =http://msdn.microsoft.com/en-us/library/system.windows.controls.uielementcollection.aspxtarget =_ blank title =新窗口> ^ ]。



所以,刚从集合中删除了一些子元素;它将立即擦除。你不应该做什么。



-SA
Here is the thing: Canvas is a parent element for collection of UIElements accessible as the property Children:
http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.children.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.uielementcollection.aspx[^].

So, just removed some child element from the collection; and it will be immediately "erased". There is nothing else you should do.

—SA


如果你保持历史采取的行动,然后你可以在历史记录的任何一点重新创建图像,从而通过简单地从历史中删除它,然后从现有的历史项目重建图像来删除一个项目。
If you maintain a history of actions taken, then you can recreate the image at any point in the history thereby "deleting" an item by simply removing it from the history and then rebuilding the image from the existing historical items.


这篇关于WPF:如何删除画布中的某些内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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