The InkPicture control provides the ability to place an image in an application and enable users to add ink on top of it. It is intended for scenarios in which ink is not recognized as text but is instead stored as ink. InkPicture control extends the default picturebox control. This post is about working with InkPicture control.
You can drag and drop this control to the form and without changing / setting any properties you can start drawing. You can modify the color, size, transparency etc of the brush using DrawingAttributes class. Also you can modify the DefaultDrawingAttributes property of the InkPicture control.
All the drawings are created as strokes, which you can access using InkPicture.Ink.Strokes. Unlike .Net Framework Picturebox, InkPicture has AutoRedraw property which helps to persist the drawing without any code. Selection
You can select and resize any stroke you created by changing EditingMode property. By default the value is Ink. For enabling selection, change it to Select.
**Delete / Erase** * Similar like Selection, changing the EditingMode from Ink or Select to Delete, helps to erase the strokes created. InkPicture control has some special properties available for Delete, it EraserMode and EraserWidth. EraserMode helps to decide what kind of erase feature is required; the values are StrokeErase and PointErase. StrokeErase mode clears the entire stroke once the mouse is move over the stroke. But PointErase clears the point where mouse is clicked. Both modes mouse cursor will be changed. EraserWidth will helps to configure the size of the eraser.
**Save as Image** * You cannot save images directly from InkPicture control. Directly GIF format only supported. Using following code, you can save the image to any format.
**Deleting all strokes** * Sometimes you may want to clear all strokes. You can use the DeleteStrokes method to achieve it.
**Drawing with custom line style or pattern** * By default InkPicture only supports drawing with normal line only. But you can override this behavior by changing the DefaultDrawingAttributes.Transparency property to 255. Thus the default stroke lines will be hidden. Here is an implementation, which draw a pattern using HatchBrush class.
The above code will draw something like this.
Note: If you draw using custom brush, selection and stroke erase will not work properly.
What do you think? I would like to hear your thoughts, suggestions, and questions in the comments section below.