Implementing User Defined Thumb Styles With LEADTOOLS Annotations

With LEADTOOLS Annotations, you can create your own custom thumbs (control points). You can create custom styles for the location, rotation center and rotation gripper thumbs.

To implement a user-defined thumb style, create a class that implements the IAnnThumbStyle interface. Then, assign your custom thumb style class to an IAnnObjectRenderer interface, which will then use your custom thumb style when rendering annotation objects.

The following example demonstrates how to create a custom thumb for an annotation object. Start with the example that you created in Implementing User-Defined Objects With LEADTOOLS Annotations.

First, create a new class, derived from the base class AnnThumbStyle, and override the AddPath method:

C#
public class AnnTriangleThumbStyle : AnnThumbStyle 
{ 
   protected override AnnThumbStyle Create() 
   { 
      return new AnnTriangleThumbStyle(); 
   } 
             
   protected override void AddPath(System.Drawing.Drawing2D.GraphicsPath path, LeadRectD rect) 
   { 
      if (path != null) 
      { 
         // Add our triangle 
         float left = (float)rect.Left; 
         float right = (float)rect.Right; 
         float width = (right - left) / 2; 
         float top = (float)rect.Top; 
         float bottom = (float)rect.Bottom; 
             
         path.AddLine(left, bottom, left + width, top); 
         path.AddLine(left + width, top, right, bottom); 
         path.AddLine(right, bottom, left, bottom); 
         path.CloseFigure(); 
      } 
   } 
} 
             

Next, assign your custom thumb style class to the annotation object renderer. Replace the code after the 'Set our renderer, same as the AnnPolylineObject' comment in InitializeTriangleObject:

C#
// Set our renderer 
             
// Get the current polyline renderer (we need to use some of the properties we are not changing) 
IAnnObjectRenderer polylineRenderer = annotations.AutomationManager.RenderingEngine.Renderers[AnnObject.PolylineObjectId]; 
             
// Create the new renderer 
IAnnObjectRenderer renderer = new AnnPolylineObjectRenderer(); 
// Use the existing label renderer. It is not being changed 
renderer.LabelRenderer = polylineRenderer.LabelRenderer; 
             
// Now, use the new triangle thumbs: 
             
// Change the location thumb style 
AnnTriangleThumbStyle locationThumb = new AnnTriangleThumbStyle(); 
locationThumb.Size = LeadSizeD.Create(72 * 2, 72 * 2); 
locationThumb.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("black"), LeadLengthD.Create(1)); 
locationThumb.Fill = AnnSolidColorBrush.Create("#7F0000FF"); 
renderer.LocationsThumbStyle = locationThumb; 
             
// Change the rotation center thumb style 
AnnTriangleThumbStyle rotateCenterThumb = new AnnTriangleThumbStyle(); 
rotateCenterThumb.Size = LeadSizeD.Create(72, 72); 
rotateCenterThumb.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("black"), LeadLengthD.Create(1)); 
rotateCenterThumb.Fill = AnnSolidColorBrush.Create("#EFFF0000"); 
renderer.RotateCenterThumbStyle = rotateCenterThumb; 
             
// Change the Rotation gripper thumb style 
AnnTriangleThumbStyle rotateGripperThumb = new AnnTriangleThumbStyle(); 
rotateGripperThumb.Size = LeadSizeD.Create(72 * 2, 72 * 2); 
rotateGripperThumb.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("black"), LeadLengthD.Create(1)); 
rotateGripperThumb.Fill = AnnSolidColorBrush.Create("#3F00FF00"); 
renderer.RotateGripperThumbStyle = rotateGripperThumb; 
             
annotations.AutomationManager.RenderingEngine.Renderers[AnnTriangleObject.MyId] = renderer; 
             

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Imaging, Medical, and Document