LEADTOOLS Annotations for WPF and Silverlight Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.22
Implementing WPF Non Automated Annotation Program
Take the following steps to create and run a program that implements non-automated annotations:
  1. Start Visual Studio .NET.
  2. Choose File->New->Project… from the menu.
  3. In the New Project dialog box, choose either "Visual C# Projects" - NET Framework 3.0 or "Visual Basic Projects" - NET Framework 3.0 in the Projects Type List, and choose "Windows Application (WPF) " in the Templates List.
  4. Type the project name as "Implementing Non Automated Annotation" in the Project Name field, and then choose OK. If desired, type a new location for your project or select a directory using the Browse button, and then choose OK .
  5. In the "Solution Explorer" window, right-click on the "References" folder (For a VB project, right-click on the project file in solution explorer), and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to Leadtools For .NET "\LEAD Technologies\LEADTOOLS 17\Bin\DotNet\Win32 " folder and select the following DLLs:
    • Leadtools.Windows.Annotations.dll
    • Leadtools.Windows.Controls.dll
    • Leadtools.Windows.Media.Transitions.dll
    Click the Select button and then press the OK button to add the above DLLs to the application.
  6. Open Window1.xaml file and replace it by the following: [Visual Basic]
                <Window x:Class="Window1"
                        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        Title="Implementing_Non_Automated_Annotation" 
                        Height="300"
                        Width="300"
                        Loaded="WindowLoaded" 
                        xmlns:Leadtools_Windows_Controls="clr-namespace:Leadtools.Windows.Controls;assembly=Leadtools.Windows.Controls"
                        >
                    <Grid>
                       <Leadtools_Windows_Controls:BitmapSourceViewer x:Name="imageViewer1" Width="NaN" Height="NaN"/>
                    </Grid>
                </Window>
                
    
    [C#]
                <Window x:Class="Implementing_Non_Automated_Annotation.Window1"
                        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        Title="Implementing_Non_Automated_Annotation" 
                        Height="300"
                        Width="300"
                        Loaded="WindowLoaded" 
                        xmlns:Leadtools_Windows_Controls="clr-namespace:Leadtools.Windows.Controls;assembly=Leadtools.Windows.Controls"
                        >
                    <Grid>
                       <Leadtools_Windows_Controls:BitmapSourceViewer x:Name="imageViewer1" Width="NaN" Height="NaN"/>
                    </Grid>
                </Window>
                
    
  7. Switch to Window1 code view (for VB project right-click Window1 in the solution explorer then select View Code and for C# project open Window1.xaml.cs file) and add the following lines at the beginning of the file: [Visual Basic]
                Imports Leadtools.Windows.Annotations
                
    
    [C#]
                using Leadtools.Windows.Annotations;
                
    
  8. Declare the following private variable: [Visual Basic]
                ' Annotation container object
                Private annContainerObj As AnnContainer
                
    
    [C#]
                // Annotation container object
                private AnnContainer annContainerObj;
                
    
  9. Add the WindowLoaded method code to class Window1: [Visual Basic]
                Private Sub WindowLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
                   imageViewer1.Source = New BitmapImage(New Uri("C:\Users\Public\Documents\LEADTOOLS Images\eye.gif"))
                   If (Not imageViewer1.Source Is Nothing) Then
                      ' initialize the AnnContainer object and associate it with imageViewer1 image
                      annContainerObj = New AnnContainer()
                      annContainerObj.Width = imageViewer1.Source.Width
                      annContainerObj.Height = imageViewer1.Source.Height
                      annContainerObj.Name = "Container"
                      annContainerObj.Visibility = Visibility.Visible
                      ' set the annContainerObj as a content of BitmapSourceViewer.
                      imageViewer1.Content = annContainerObj
                      ' create Annotation Note Object and add it to the container
                      annContainerObj.Children.Add(CreateAnnNoteObject(New Rect(annContainerObj.Width / 2, annContainerObj.Height / 2, (annContainerObj.Width / 4) - 1, (annContainerObj.Height / 4) - 1)))
                   End If
                End Sub
                
    
    [C#]
                private void WindowLoaded(object sender, RoutedEventArgs e)
                {
                   imageViewer1.Source = new BitmapImage(new Uri(@"C:\Users\Public\Documents\LEADTOOLS Images\eye.gif"));
                   if(imageViewer1.Source != null)
                   {
                      // initialize the AnnContainer object and associate it with imageViewer1 image
                      annContainerObj = new AnnContainer();
                      annContainerObj.Width = imageViewer1.Source.Width;
                      annContainerObj.Height = imageViewer1.Source.Height;
                      annContainerObj.Name = "Container";
                      annContainerObj.Visibility = Visibility.Visible;
                      // set the annContainerObj as a content of BitmapSourceViewer.
                      imageViewer1.Content = annContainerObj;
                      // create Annotation Note Object and add it to the container
                      annContainerObj.Children.Add(CreateAnnNoteObject(new Rect(annContainerObj.Width / 2, annContainerObj.Height / 2, (annContainerObj.Width / 4) - 1, (annContainerObj.Height / 4) - 1)));
                   }
                }
                
    
  10. Add the CreateAnnNoteObject function code to class Window1: [Visual Basic]
                Private Function CreateAnnNoteObject(ByVal boundingRect As Rect) As AnnObject
                   Dim annNoteObj As AnnNoteObject = New AnnNoteObject()
                   annNoteObj.Text = "This is my Text"
                   annNoteObj.TextBrush = Brushes.Red
                   annNoteObj.Stroke = Brushes.Red
                   annNoteObj.StrokeThickness = 3
                   annNoteObj.Fill = Brushes.Yellow
                   annNoteObj.FontFamily = New FontFamily("Arial")
                   annNoteObj.FontSize = 14
                   annNoteObj.FontWeight = FontWeights.Bold
                   annNoteObj.Hyperlink = "Notepad.exe"
                   annNoteObj.Left = boundingRect.Left
                   annNoteObj.Top = boundingRect.Top
                   annNoteObj.Width = boundingRect.Width
                   annNoteObj.Height = boundingRect.Height
                   Return annNoteObj
                End Function
                
    
    [C#]
                private AnnObject CreateAnnNoteObject(Rect boundingRect)
                {
                   AnnNoteObject annNoteObj = new AnnNoteObject();
                   annNoteObj.Text = "This is my Text";
                   annNoteObj.TextBrush = Brushes.Red;
                   annNoteObj.Stroke = Brushes.Red;
                   annNoteObj.StrokeThickness = 3;
                   annNoteObj.Fill = Brushes.Yellow;
                   annNoteObj.FontFamily = new FontFamily("Arial");
                   annNoteObj.FontSize = 14;
                   annNoteObj.FontWeight = FontWeights.Bold;
                   annNoteObj.Hyperlink = "Notepad.exe";
                   annNoteObj.Left = boundingRect.Left;
                   annNoteObj.Top = boundingRect.Top;
                   annNoteObj.Width = boundingRect.Width;
                   annNoteObj.Height = boundingRect.Height;
                   return annNoteObj;
                }
                
    
  11. Build, and Run the program to test it.