InkOverlay.Draw Method
InkOverlay.Draw Method |
Sets a rectangle in which to redraw the ink within the InkOverlay object.
Definition
Visual Basic .NET Public Sub Draw( _
ByVal rDrawRect As Rectangle _
)C# public void Draw(
Rectangle rDrawRect
);Managed C++ public: void Draw(
Rectangle *rDrawRect
);
Parameters
rDrawRect System.Drawing.Rectangle. The rectangle in which to redraw the ink, in pixel coordinates.
Exceptions
ObjectDisposedException : The InkOverlay object is disposed.
Remarks
When the rDrawRect parameter is
null
(Nothing
in Microsoft® Visual Basic® .NET), the entire window is redrawn.A good use of this method is to redraw strokes that have been programmically changed. You can also call the Control.Invalidate method, but this causes a redrawing off all of the InkOverlay object's strokes. You can also call the Renderer.Draw method for this purpose, but the Renderer object is not able to draw any strokes as selected because it has no knowledge of which strokes are in the Selection collection.
Note: The AutoRedraw property must be set to true for the drawing to occur.
Examples
[C#]
This C# example is a method that changes the color of all the strokes in a Strokes collection that belong to the Ink object associated with an InkOverlay object, theInkOverlay. Changing the DrawingAttributes property of a Stroke object is not automatically and immediately visible. You can call the Invalidate or Refresh method on the control associated with theInkOverlay, but this causes a redrawing of all the Stroke objects in theInkOverlay. To achieve better performance, use the Draw method on the bounding box of the Strokes collection. Note that this means converting the bounding box from ink space coordinates to pixel coordinates.
private void ChangeColor(Strokes theStrokes, Color newColor) { // Change the color of theStrokes foreach (Stroke stroke in theStrokes) { stroke.DrawingAttributes.Color = newColor; } // Convert bounding box to pixel coordinates Graphics g = CreateGraphics(); Rectangle strokesBounds = theStrokes.GetBoundingBox(); Point topLeft = strokesBounds.Location; Point bottomRight = strokesBounds.Location + strokesBounds.Size; theInkOverlay.Renderer.InkSpaceToPixel(g, ref topLeft); theInkOverlay.Renderer.InkSpaceToPixel(g, ref bottomRight); g.Dispose() strokesBounds = new Rectangle(topLeft, new Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y)); // Redraw the strokes theInkOverlay.Draw(strokesBounds); }
[VB.NET]
This Visual Basic .NET example is a method that changes the color of all the strokes in a Strokes collection that belong to the Ink object associated with an InkOverlay object, theInkOverlay. Changing the DrawingAttributes property of a Stroke object is not automatically and immediately visible. You can call the Invalidate or Refresh method on the control associated with theInkOverlay, but this causes a redrawing of all the Stroke objects in theInkOverlay. To achieve better performance, use the Draw method on the bounding box of the Strokes collection. Note that this means converting the bounding box from ink space coordinates to pixel coordinates.
Private Sub ChangeColor(ByVal theStrokes As Strokes, ByVal newColor As Color) ' Change the color of theStrokes Dim theStroke As Stroke For Each theStroke In theStrokes theStroke.DrawingAttributes.Color = newColor Next 'Convert bounding box to pixel coordinates Dim g As Graphics = CreateGraphics() Dim strokesBounds As Rectangle = theStrokes.GetBoundingBox() Dim topLeft As Point = strokesBounds.Location Dim bottomRight As Point = New Point(strokesBounds.Right, strokesBounds.Bottom) theInkOverlay.Renderer.InkSpaceToPixel(g, topLeft) theInkOverlay.Renderer.InkSpaceToPixel(g, bottomRight) g.Dispose() strokesBounds = New Rectangle(topLeft, _ New Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y)) 'Redraw the strokes theInkOverlay.Draw(strokesBounds) End Sub
See Also