Question

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?

Was it helpful?

Solution

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top