InkCanvas Eraser

回眸只為那壹抹淺笑 提交于 2020-02-03 02:24:26

问题


I have sketchpad as InkCanvas; I want to change size of eraser so I've written:

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

Try this:

  1. Select eraser by pressing e, Eraser stylusTip will appears Rectangular
  2. Press + sign to increase size , you will not see any changes. Why?
  3. Now you press i to change editing mode, ink tip will appears.
  4. Press e again to reswitch to Eraser. You will see that eraser shape has been changed.

Why not after pressing + sign?


回答1:


From the help:

"If you change the EraserShape, the cursor rendered on the InkCanvas is not updated until the next EditingMode change."

I tested the following code and it works fine:

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;
}


来源:https://stackoverflow.com/questions/5482298/inkcanvas-eraser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!