0

我有画板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

尝试这个:

  1. 按e选择橡皮擦,橡皮擦笔尖会出现矩形
  2. 按+号增加大小,你不会看到任何变化。为什么?
  3. 现在您按 i 更改编辑模式,将出现墨水提示。
  4. 再次按 e 可重新切换到橡皮擦。您会看到橡皮擦形状已更改。

为什么不按+号后?

4

1 回答 1

2

帮助

“如果您更改 EraserShape,则在 InkCanvas 上呈现的光标不会更新,直到下一次 EditingMode 更改。”

我测试了以下代码,它工作正常:

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;
}
于 2011-04-19T08:12:12.023 回答