OnCustomAnnotationPaint Event (GdViewer)
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 GdViewer.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.
In JScript, you can handle the events defined by another class, but you cannot define your own.
How to add this event to your GdViewer control.
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 GdViewer1 control has been properly integrated.
Friend WithEvents GdViewer1 As GdPicture14.GdViewer
'Add the event.
AddHandler GdViewer1.OnCustomAnnotationPaint, AddressOf GdViewer1_OnCustomAnnotationPaint
'Define the event.
Sub GdViewer1_OnCustomAnnotationPaint(ByVal Annot As GdPicture14.Annotations.AnnotationCustom, ByVal g As System.Drawing.Graphics) Handles GdViewer1.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 GdViewer1 control has been properly integrated.
//Add the event.
GdViewer1.OnCustomAnnotationPaint += GdViewer1_OnCustomAnnotationPaint;
//Define the event.
void GdViewer1_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;
}
}