问题
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:
- Select eraser by pressing e, Eraser stylusTip will appears Rectangular
- Press + sign to increase size , you will not see any changes. Why?
- Now you press i to change editing mode, ink tip will appears.
- 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