LEAD Technologies, Inc

Advanced Magnifying Glass

Take the following steps to create a project that uses advanced features of the Magnifying Glass:
  1. Start Visual Studio .NET.
  2. Open the project that you created in the tutorial, Using the Magnifying Glass.
  3. In the "Solution Explorer" window, right-click on the "References" folder, and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to Leadtools For .NET "<LEADTOOLS_INSTALLDIR>\Bin\DotNet\Win32 " folder and select the following DLLs:
    • Leadtools.Drawing.dll
  4. Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code ) and add the following lines at the beginning of the file (after the existing Imports / using statements):
  5. [Visual Basic]
          
    
                 Imports System.Drawing.Drawing2D
                 Imports Leadtools.Drawing
                 
    
    
        
    
    [C#]
          
    
                 using System.Drawing.Drawing2D;
                 using Leadtools.Drawing;
                 
    
    
        
    
  6. Add the following code to derive your own class from RasterMagnifyGlass, and override OnPaintBorder, OnPaintCrosshair and OnPaintImage. For Visual Basic, put this code at the end of the file. For #, put this code just inside the namespace.

    [Visual Basic]
                   ' My own class, derived from Leadtools.WinForms.RasterMagnifyGlass
                   Public Class MyMagGlass : Inherits RasterMagnifyGlass
                      Protected Overrides Sub OnPaintBorder(ByVal g As Graphics, ByVal centerPoint As Point)
                         g.DrawEllipse(Pens.Blue, centerPoint.X - (Size.Width / 2), centerPoint.Y - (Size.Height / 2), Size.Width - 1, Size.Height - 1)
                      End Sub
                 
                      Protected Overrides Sub OnPaintCrosshair(ByVal g As Graphics, ByVal centerPoint As Point)
                         g.DrawRectangle(Pens.Red, centerPoint.X - 10, centerPoint.Y - 10, 20, 20)
                      End Sub
                      
                      Protected Overrides Sub OnPaintImage(ByVal g As Graphics, ByVal centerPoint As Point)
                         Dim t As Transformer = New Transformer(Viewer.Transform)
                         Dim rcDst As LeadRect = New LeadRect(centerPoint.X - (Size.Width / 2), centerPoint.Y - (Size.Height / 2), Size.Width - 1, Size.Height - 1)
                         Dim rcTemp As Rectangle = New Rectangle(rcDst.Left, rcDst.Top, rcDst.Width, rcDst.Height)
                         rcTemp = Rectangle.Round(rcTemp)
                         Dim rcSrc As LeadRect = New LeadRect(rcTemp.Left, rcTemp.Top, rcTemp.Width, rcTemp.Height)
                         
                         Dim gstate As GraphicsState = g.Save()
                         Dim path As GraphicsPath = New GraphicsPath()
                         path.AddEllipse(rcTemp)
                         Dim rgn As Region = New Region(path)
                         path.Dispose()
                         
                         Viewer.Image.DisableEvents()
                         Dim contrast As Integer = Viewer.Image.PaintContrast
                         Viewer.Image.PaintContrast = 1000
                         
                         g.Clip = rgn
                         RasterImagePainter.Paint(Viewer.Image, g, rcSrc, rcSrc, rcDst, rcDst, Viewer.PaintProperties)
                         Viewer.Image.PaintContrast = contrast
                         Viewer.Image.EnableEvents()
                         
                         g.Restore(gstate)
                         rgn.Dispose()
                      End Sub
                   End Class
                 
    
  7. [C#]
          
    
                   //My own class, derived from Leadtools.WinForms.RasterMagnifyGlass
                   public class MyMagGlass : RasterMagnifyGlass
                   {
                      protected override void OnPaintBorder(Graphics g, Point centerPoint)
                      {
                         g.DrawEllipse(Pens.Blue, centerPoint.X - (Size.Width / 2), centerPoint.Y - (Size.Height / 2), Size.Width - 1, Size.Height - 1);
                      }
                
                      protected override void OnPaintCrosshair(Graphics g, Point centerPoint)
                      {
                         g.DrawRectangle(Pens.Red, centerPoint.X - 10, centerPoint.Y - 10, 20, 20);
                      }
                      
                      protected override void OnPaintImage(Graphics g, Point centerPoint)
                      {
                         Transformer t = new Transformer(Viewer.Transform);
                         LeadRect rcDst = new LeadRect(centerPoint.X - (Size.Width / 2), centerPoint.Y - (Size.Height / 2), Size.Width - 1, Size.Height - 1);
                         Rectangle rcTemp = new Rectangle(rcDst.Left, rcDst.Top, rcDst.Width, rcDst.Height);
                         rcTemp = Rectangle.Round(rcTemp);
                         LeadRect rcSrc = new LeadRect(rcTemp.Left, rcTemp.Top, rcTemp.Width, rcTemp.Height);
                         GraphicsState gstate = g.Save();
                         GraphicsPath path = new GraphicsPath();
                         path.AddEllipse(rcTemp);
                         Region rgn = new Region(path);
                         path.Dispose();
                         Viewer.Image.DisableEvents();
                         int contrast = Viewer.Image.PaintContrast;
                         Viewer.Image.PaintContrast = 1000;
                         g.Clip = rgn;
                         RasterImagePainter.Paint(Viewer.Image, g, rcSrc, rcSrc, rcDst, rcDst, Viewer.PaintProperties);
                         Viewer.Image.PaintContrast = contrast;
                         Viewer.Image.EnableEvents();
                         g.Restore(gstate);
                         rgn.Dispose();
                      }
                   }
                 
    
    
        
    
  8. In the code for the Load event for Form1, add the following line, just before the line that sets the InteractiveMode property:

    [Visual Basic]
                  
                 RasterImageViewer1.MagnifyGlass = New MyMagGlass 'set the MagGlass
                 
    
    [C#]
                  
                 rasterImageViewer1.MagnifyGlass = new MyMagGlass(); //set the MagGlass to my derived class
                 
    
  9. Build, and Run the program to test it.

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.