How To Delete Or Erase Ink
There are two ways to remove ink from an Ink Collector object. The first way is simple and removes all ink strokes. The second way is more complicated, yet ideal, because it acts just like an eraser would.
Deleting All Ink Strokes
You can quickly delete all ink strokes within an Ink Collector object with the following code.
myInkCollector.Ink.DeleteStrokes();
Refresh();
Erasing Ink
Erasing ink is somewhat more difficult than drawing it.
First you need to create a method that will perform hit tests to see where the mouse cursor is located. If it is close to an ink stroke, the stroke will be removed.
{
int HitTestRadius = 3;
// remove ink strokes within the hit radius of the mouse
Strokes strokesHit = myInkCollector.Ink.HitTest(pt, HitTestRadius);
if (null!=currentStroke && strokesHit.Contains(currentStroke))
{
strokesHit.Remove(currentStroke);
}
// delete all strokes that are in the hit radius
myInkCollector.Ink.DeleteStrokes(strokesHit);
if (strokesHit.Count > 0)
{
// repaint the screen
this.Refresh();
}
}
Next you want to be able to call the EraseStrokes method when the mouse is moving over the Ink Collector.
Add a MouseMove method to the object that your Ink Collector is linked to (e.g., the Form).
Next add code to this method that will check if the stylus button / mouse button is pushed. If it is, it will call EraseStrokes to check to see which strokes to erase.
{
// if the collector is not collecting ink and the mouse button is pushed then erase
if (!myInkCollector.Enabled && (MouseButtons.None != MouseButtons))
{
Point pt = new Point(e.X, e.Y);
// Convert the specified point from pixel to ink space coordinates
myInkCollector.Renderer.PixelToInkSpace(this.Handle, ref pt);
EraseStrokes(pt,null);
}
}