Inkcanvas橡皮擦
-
14-11-2019 - |
题
我有sketchpad作为InkCanvas
;我想改变橡皮擦的大小,所以我写了:
Private Sub Sketchpad_KeyDown(sender As System.Object, e As System.Windows.Input.KeyEventArgs) Handles Sketchpad.KeyDown
If e.Key = Key.OemMinus Then
' Decrease size of Eraser to 5*5
Sketchpad.EraserShape = New RectangleStylusShape(5, 5)
End If
If e.Key = Key.OemPlus Then
' Increase size of Eraser to 50*50
Sketchpad.EraserShape = New RectangleStylusShape(50, 50)
End If
If e.Key = Key.I Then
' Change editing mode to Ink
Sketchpad.EditingMode = InkCanvasEditingMode.Ink
End If
If e.Key = Key.E Then
' Change editing mode to Eraser
Sketchpad.EditingMode = InkCanvasEditingMode.EraseByPoint
End If
End Sub
.
试试:
- 通过按E选择橡皮擦,橡皮擦曲线将出现矩形
- 按+符号增加大小,您不会看到任何更改。为什么?
- 现在你按i要更改编辑模式,将出现墨滴。
- 再次按E再次擦拭橡皮擦。你会看到橡皮擦形状已经改变。
为什么不按+签名后?
解决方案
从帮助:
“如果更改erasershape,则在Inkcanvas上呈现的光标不会更新,直到下一个编辑介绍更改。”
我测试了以下代码,它工作正常:
if (e.Key == Key.OemMinus)
{
ink.EraserShape = new RectangleStylusShape(5, 5);
var editMode = ink.EditingMode;
ink.EditingMode = InkCanvasEditingMode.None;
ink.EditingMode = editMode;
}
if (e.Key == Key.OemPlus)
{
ink.EraserShape = new RectangleStylusShape(50, 50);
var editMode = ink.EditingMode;
ink.EditingMode = InkCanvasEditingMode.None;
ink.EditingMode = editMode;
}
. 不隶属于 StackOverflow