←Select platform

AnnSnapToGridOptions Class

Summary

Options for annotation snap to grid behavior in annotation automation design mode.

Syntax

C#
VB
C++
public class AnnSnapToGridOptions 
  
Public Class AnnSnapToGridOptions  
public ref class AnnSnapToGridOptions  

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 overlayed on the image beging annotated. When creating annotations in design mode, each point snaps to the nearest grid point. This beavior 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 overlayed 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:

  • GridColor = Color.Red
  • LineSpacing = 20
  • LineStyle = DashStyle.Solid

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

This example:

  • Gets the current state of the snap-to-grid

  • Changes the snap to grid to grid size of 10, lines every ten row of dots, solid red lines

  • Enables the snap to grid

    C#
    VB
    using Leadtools.Windows.Controls; 
    using Leadtools.Windows.Annotations; 
    using Leadtools.Demos; 
    using Leadtools.Help; 
     
    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 = Colors.Red; 
       options.GridLength = 10; 
       options.LineSpacing = 10; 
       options.LineStyle = DashStyles.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); 
     
       MessageBox.Show(sb.ToString(), title); 
    } 
    Imports Leadtools.Windows.Controls 
    Imports Leadtools.Windows.Annotations 
     
    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 = Colors.Red 
       options.GridLength = 10 
       options.LineSpacing = 10 
       options.LineStyle = DashStyles.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()) 
     
       MessageBox.Show(sb.ToString(), title) 
    End Sub 

Requirements

Target Platforms

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

Leadtools.Windows.Annotations Assembly