Implementing User Defined Thumb Styles With LEADTOOLS Annotations

Show in webframe

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

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

The following example demonstrates how to create a custom thumbs 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 our new renderer
            IAnnObjectRenderer renderer = new AnnPolylineObjectRenderer();
            // Use the existing label renderer, we are not changing that
            renderer.LabelRenderer = polylineRenderer.LabelRenderer;
            
            // Now, use our 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 rotate 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 rotate 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;
            

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.