LEADTOOLS Annotations (Leadtools.Annotations assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
BeforeDrawingObjects Event
See Also 
Leadtools.Annotations Namespace > AnnContainer Class : BeforeDrawingObjects Event



The BeforeDrawingObjects Event is available in LEADTOOLS Document and Medical Imaging toolkits.

Occurs during drawing before the objects are drawn.

Syntax

Visual Basic (Declaration) 
Public Event BeforeDrawingObjects As EventHandler(Of AnnPaintEventArgs)
Visual Basic (Usage)Copy Code
Dim instance As AnnContainer
Dim handler As EventHandler(Of AnnPaintEventArgs)
 
AddHandler instance.BeforeDrawingObjects, handler
C# 
public event EventHandler<AnnPaintEventArgs> BeforeDrawingObjects
C++/CLI 
public:
event EventHandler<AnnPaintEventArgs^>^ BeforeDrawingObjects

Event Data

The event handler receives an argument of type AnnPaintEventArgs containing data related to this event. The following AnnPaintEventArgs properties provide information specific to this event.

PropertyDescription
Graphics Gets the graphics used to paint.

Example

This example will draw a grid 100 pixels apart on the surface of the viewer before the container is drawn.

Visual BasicCopy Code
Public theContainer As AnnContainer
Public Sub AnnContainer_BeforeDrawingObjects(ByVal container As AnnContainer)
   ' theContainer is set so that it can be accessed in the container_BeforeDrawingObjects event
   theContainer = container
   AddHandler container.BeforeDrawingObjects, AddressOf container_BeforeDrawingObjects
End Sub
Private Sub container_BeforeDrawingObjects(ByVal sender As Object, ByVal e As AnnPaintEventArgs)
   ' draw a grid, 100 pixels apart

   Dim graphics As Graphics = e.Graphics

   ' set the current transform from the container
   graphics.MultiplyTransform(theContainer.Transform)

   ' get the bounds in pixels
   Dim rc As AnnRectangle = theContainer.Bounds.ConvertTo(theContainer.UnitConverter, AnnUnit.Pixel)

   Dim p As Pen = New Pen(Color.FromArgb(128, 255, 255, 255))
   Try
      ' draw the grid
      Dim x As Single = rc.Left
      Do While x <= rc.Right
         graphics.DrawLine(p, x, 0, x, rc.Bottom)
         x += 100
      Loop

      Dim y As Single = rc.Top
      Do While y <= rc.Bottom
         graphics.DrawLine(p, 0, y, rc.Right, y)
         y += 100
      Loop
   Finally
      CType(p, IDisposable).Dispose()
   End Try
End Sub
C#Copy Code
public AnnContainer theContainer;
public void AnnContainer_BeforeDrawingObjects(AnnContainer container)
{
   // theContainer is set so that it can be accessed in the container_BeforeDrawingObjects event
   theContainer = container;
   container.BeforeDrawingObjects += new EventHandler<AnnPaintEventArgs>(container_BeforeDrawingObjects);
}
private void container_BeforeDrawingObjects(object sender, AnnPaintEventArgs e)
{
   // draw a grid, 100 pixels apart

   Graphics graphics = e.Graphics;

   // set the current transform from the container
   graphics.MultiplyTransform(theContainer.Transform);

   // get the bounds in pixels
   AnnRectangle rc = theContainer.Bounds.ConvertTo(theContainer.UnitConverter, AnnUnit.Pixel);

   using (Pen p = new Pen(Color.FromArgb(128, 255, 255, 255)))
   {
      // draw the grid
      for (float x = rc.Left; x <= rc.Right; x += 100)
         graphics.DrawLine(p, x, 0, x, rc.Bottom);

      for (float y = rc.Top; y <= rc.Bottom; y += 100)
         graphics.DrawLine(p, 0, y, rc.Right, y);
   }
}

Remarks

You can prevent the AnnContainer from raising this event by calling DisableDrawObjectEvents. You can re-enable the raising of this event by calling EnableDrawObjectEvents.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also

Leadtools.Annotations requires a Document or Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features