LEADTOOLS Annotations (Leadtools.Annotations assembly)

AnnSnapToGridOptions Class

Show in webframe
Example 





Members 
Options for annotation snap to grid behavior in annotation automation design mode.
Object Model
Syntax
public class AnnSnapToGridOptions : System.ICloneable  
'Declaration
 
Public Class AnnSnapToGridOptions 
   Implements System.ICloneable 
'Usage
 
Dim instance As AnnSnapToGridOptions

            

            
public ref class AnnSnapToGridOptions : public System.ICloneable  
Remarks

The AnnSnapToGridOptions class is used with the AnnContainer.SnapToGridOptions property to get or set the annotation snap to grid behavior in annotation automation design mode. You can then enable or disable snapping to grid by using the AnnContainer.EnableSnapToGrid property.

The snap-to-grid feature is used in annotation automation design mode to allow the user to precisely draw, locate, and align annotation objects. When snap-to-grid is enabled (AnnContainer.EnableSnapToGrid is set to true), a grid pattern consisting of dots and lines is overlaid on the image being annotated. When creating annotations in design mode, each point snaps to the nearest grid point. This behavior holds for creating any annotation object except the freehand annotation. When creating a freehand annotation, the individual points do not snap to the nearest grid point because this would adversely affect the behavior of the freehand. The snap-to-grid feature affects the moving of all annotations object types in design mode, in that the bounding box of the annotation object snaps to the nearest grid point.

The grid that is overlaid can be customized by color (GridColor), grid spacing (GridLength), and line frequency (LineSpacing). For example, to display a red grid that has a dot pattern every 20 pixels, and solid lines every 100 pixels, you would set:

The lines of the grid can be removed completely by setting GridColor to be Color.Transparent. The lines of the grid can be drawn in any style (LineStyle). The grid itself can be hidden by setting ShowGrid to false so that the snap-to-grid feature is still on without the grid being overlaid on the image. Conversely, the grid can be displayed by setting ShowGrid to true while disabling the snap-to-grid-behavior by setting AnnContainer.EnableSnapToGrid to true.

Setting AutoChangeGridLength to true affects the grid density when zooming. The effect is that when zooming to 200, the density of the dot pattern doubles. When zooming to 400, the density doubles again The density doubles at 200, 400, 800, 1600 and so on as long as it is meaningful to double the density. In other words, if doubling the dot density would create a dot where no pixel exists when viewing at 100, then the dot density will not change. The following examples illustrate this.

Example 1: GridLength is 10

The dot density doubles at 200 because 10 is evenly divisible by 2.

The dot density does not double again at 400 because 10 do not evenly divide 4.

Example 2: GridLength is 20

The dot density doubles at 200, and doubles again at 400.

The dot density does not double again at 800 because 20 does not divide 8 evenly.

Example 3: GridLength is 21

The dot density doubles at 200, and doubles again at 400.

The dot density never changes because 21 is a prime number.

The snap-to-grid behavior can be turned on our off in annotation automation mode by right-clicking on a part of the image that does not contain an annotation, and selecting the Snap To Grid option from the context menu. The snap-to-grid behavior can be customized in annotation automation mode by:

  1. Right-clicking on a part of the image that does not contain an annotation

  2. Selecting Default Properties

  3. Clicking on the "Snap to Grid..." menu option

Example
Copy Code  
Imports Leadtools
Imports Leadtools.Annotations
Imports Leadtools.Codecs
Imports Leadtools.WinForms

Private Shared Sub SnapToGridExample(ByVal automation As AnnAutomation)
   ' First use default
   automation.Container.EnableSnapToGrid = True
   automation.EnableSnapToGrid = True
   DisplaySnapToGrid(automation, "Original settings")
   ' Change snap-to-grid to grid size of 10, lines every ten row of dots, solid red lines, and enable it
   Dim options As New AnnSnapToGridOptions()
   options.AutoChangeGridLength = True
   options.EnableSnap = True
   options.ShowGrid = True
   options.GridColor = Color.Red
   options.GridLength = 10
   options.LineSpacing = 10
   options.LineStyle = DashStyle.Solid

   automation.Container.SnapToGridOptions = options
   DisplaySnapToGrid(automation, "New settings")
End Sub

Private Shared Sub DisplaySnapToGrid(ByVal automation As AnnAutomation, ByVal title As String)
   Dim options As AnnSnapToGridOptions = automation.Container.SnapToGridOptions

   Dim sb As New StringBuilder()
   sb.AppendLine("Grid color: " + options.GridColor.ToString())
   sb.AppendLine("Grid length: " + options.GridLength.ToString())
   sb.AppendLine("Line spacing: " + options.LineSpacing.ToString())
   sb.AppendLine("Line style: " + options.LineStyle.ToString())
   sb.AppendLine("Enable snap: " + options.EnableSnap.ToString())
   sb.AppendLine("Show grid: " + options.ShowGrid.ToString())
   sb.AppendLine("Auto-change grid length: " + options.AutoChangeGridLength.ToString())

   System.Windows.Forms.MessageBox.Show(sb.ToString(), title)
End Sub
using Leadtools;
using Leadtools.Annotations;
using Leadtools.Codecs;
using Leadtools.WinForms;

private static void SnapToGridExample(AnnAutomation automation)
{
   // First use default
   automation.Container.EnableSnapToGrid = true;
   automation.EnableSnapToGrid = true;
   DisplaySnapToGrid(automation, "Original settings");
   // Change snap-to-grid to grid size of 10, lines every ten row of dots, solid red lines, and enable it
   AnnSnapToGridOptions options = new AnnSnapToGridOptions();
   options.AutoChangeGridLength = true;
   options.EnableSnap = true;
   options.ShowGrid = true;
   options.GridColor = Color.Red;
   options.GridLength = 10;
   options.LineSpacing = 10;
   options.LineStyle = DashStyle.Solid;

   automation.Container.SnapToGridOptions = options;
   DisplaySnapToGrid(automation, "New settings");
}

private static void DisplaySnapToGrid(AnnAutomation automation, string title)
{
   AnnSnapToGridOptions options = automation.Container.SnapToGridOptions;

   StringBuilder sb = new StringBuilder();
   sb.AppendLine("Grid color: " + options.GridColor);
   sb.AppendLine("Grid length: " + options.GridLength);
   sb.AppendLine("Line spacing: " + options.LineSpacing);
   sb.AppendLine("Line style: " + options.LineStyle);
   sb.AppendLine("Enable snap: " + options.EnableSnap);
   sb.AppendLine("Show grid: " + options.ShowGrid);
   sb.AppendLine("Auto-change grid length: " + options.AutoChangeGridLength);

   System.Windows.Forms.MessageBox.Show(sb.ToString(), title);
}
Requirements

Target Platforms

See Also

Reference

AnnSnapToGridOptions Members
Leadtools.Annotations Namespace

 

 


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