GdPicture.NET.14.API
GdPicture14 Namespace / AnnotationManager Class / OnCustomAnnotationPaint Event
Example





In This Topic
OnCustomAnnotationPaint Event (AnnotationManager)
In This Topic
This event is raised when a custom annotation is to be rendered. Your custom ModelID identifier, that you have defined when adding the custom annotation, should be used internally in this event to render the required annotation, as it is demontrated in the Example section below.

Please check the corresponded AnnotationManager.OnCustomAnnotationPaintEventHandler for given parameters.

The bounding box for the annotation appearance, that you need to follow, is defined by values x, y, w, h, where x and y define the coordinates of the top-left corner of the box as x = (Annot.Left - Annot.Width) / 2, y = (Annot.Top - Annot.Height) / 2, w defines the width of the box as w = Annot.Width and y defines the height of the box as y = Annot.Height.

The measurement unit used for specified dimensions and sizes is expressed in inches. The rotation, if any, is handled by the component, which automatically sets the required transformation.

Syntax
'Declaration
 
Public Event OnCustomAnnotationPaint As AnnotationManager.OnCustomAnnotationPaintEventHandler
public event AnnotationManager.OnCustomAnnotationPaintEventHandler OnCustomAnnotationPaint
public event OnCustomAnnotationPaint: AnnotationManager.OnCustomAnnotationPaintEventHandler; 
In JScript, you can handle the events defined by another class, but you cannot define your own.
public: __event AnnotationManager.OnCustomAnnotationPaintEventHandler* OnCustomAnnotationPaint
public:
event AnnotationManager.OnCustomAnnotationPaintEventHandler^ OnCustomAnnotationPaint
Remarks
Be aware that this event is not supported by the COM Interop edition.

You can find the use of this event in our Annotations Sample here.

Please respect the annotation bounding box coordinates and sizes expressed in inches, as they are described in the Summary section above.

Example
How to add this event to your AnnotationManager object.

This example introduces two custom annotations - the triangle one with the ModelID = 1 and the cross one with the ModelID = 2.

'We assume that the annotationManager object has been integrated into your application.
Friend WithEvents annotationManager As GdPicture14.AnnotationManager
            
'Add the event.
AddHandler annotationManager.OnCustomAnnotationPaint, AddressOf annotationManager_OnCustomAnnotationPaint
            
'Define the event.
Sub annotationManager_OnCustomAnnotationPaint(ByVal Annot As GdPicture14.Annotations.AnnotationCustom, ByVal g As System.Drawing.Graphics) Handles annotationManager.OnCustomAnnotationPaint
    Select Case Annot.ModelID
        Case 1 'triangle annotation
            Using gp As New Drawing.Drawing2D.GraphicsPath
                gp.AddLine(New PointF(Annot.Left - Annot.Width / 2, Annot.Top + Annot.Height / 2), New PointF(Annot.Left, Annot.Top - Annot.Height / 2))
                gp.AddLine(New PointF(Annot.Left, Annot.Top - Annot.Height / 2), New PointF(Annot.Left + Annot.Width / 2, Annot.Top + Annot.Height / 2))
                gp.CloseFigure()
                g.DrawPath(New Pen(Brushes.Red, 0.1), gp)
            End Using
        Case 2 'cross annotation
            g.DrawLine(New Pen(Brushes.Red, 0.1), New PointF(Annot.Left - Annot.Width / 2, Annot.Top - Annot.Height / 2), New PointF(Annot.Left + Annot.Width / 2, Annot.Top + Annot.Height / 2))
            g.DrawLine(New Pen(Brushes.Red, 0.1), New PointF(Annot.Left - Annot.Width / 2, Annot.Top + Annot.Height / 2), New PointF(Annot.Left + Annot.Width / 2, Annot.Top - Annot.Height / 2))
    End Select
End Sub
//We assume that the annotationManager object has been integrated into your application.
            
//Add the event.
annotationManager.OnCustomAnnotationPaint += annotationManager_OnCustomAnnotationPaint;
            
//Define the event.
void annotationManager_OnCustomAnnotationPaint(GdPicture14.Annotations.AnnotationCustom Annot, System.Drawing.Graphics g)
{
    switch (Annot.ModelID)
    {
        case 1:
            using (System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath())
            {
                gp.AddLine(new PointF(Annot.Left - Annot.Width / 2, Annot.Top + Annot.Height / 2), new PointF(Annot.Left, Annot.Top - Annot.Height / 2));
                gp.AddLine(new PointF(Annot.Left, Annot.Top - Annot.Height / 2), new PointF(Annot.Left + Annot.Width / 2, Annot.Top + Annot.Height / 2));
                gp.CloseFigure();
                g.DrawPath(new Pen(System.Drawing.Brushes.Red, 0.1f), gp);
            }
            break;
        case 2:
            g.DrawLine(new Pen(System.Drawing.Brushes.Red, 0.1f), new PointF(Annot.Left - Annot.Width / 2, Annot.Top - Annot.Height / 2), new PointF(Annot.Left + Annot.Width / 2, Annot.Top + Annot.Height / 2));
            g.DrawLine(new Pen(System.Drawing.Brushes.Red, 0.1f), new PointF(Annot.Left - Annot.Width / 2, Annot.Top + Annot.Height / 2), new PointF(Annot.Left + Annot.Width / 2, Annot.Top - Annot.Height / 2));
            break;
        default: break;
    }
}
See Also