iT邦幫忙

0

WPF Canvas畫板 橡皮擦功能

我使用WPF的Canvas畫布 要實現擦板的功能,將多個Rectangle疊再一起時,只能觸發最上層的Rectangle 如下圖
https://ithelp.ithome.com.tw/upload/images/20180916/201117438bRpWFOAAJ.png
請問該如何做出像下圖的功能
https://ithelp.ithome.com.tw/upload/images/20180916/20111743O0zHBNpefh.png
public void Image_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
System.Windows.Rect Rect;
RectangleGeometry RectangleGeometry;
DesignerItem DesignerItem = (DesignerItem)sender;
Point MouseScreenPos = new Point();
MouseScreenPos = e.GetPosition(DesignerItem);
if (DesignerItem.Content.ToString() == "System.Windows.Shapes.Rectangle")
{
Rectangle EraserPen = (Rectangle)DesignerItem.Content;
PathGeometry ClipPathGeometry = new PathGeometry();
ClipPathGeometry = (PathGeometry)EraserPen.Clip;
RectangleGeometry = new RectangleGeometry();
Rect = new System.Windows.Rect();
Rect.Width = Rect.Height = 200;
Rect.X = MouseScreenPos.X - 100;
Rect.Y = MouseScreenPos.Y - 100;
RectangleGeometry.Rect = Rect;
EraserPen.Clip = Geometry.Combine(ClipPathGeometry, RectangleGeometry, GeometryCombineMode.Exclude, null);
}
}
}

尚未有邦友回答

立即登入回答