Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.12.21
Painting Pages and Zones
Take the following steps to start a project and to add some code that demonstrates how to draw pages and zones:
  1. Start with the program you created in Working with Recognition Results.
  2. In the "Solution Explorer" window, right-click on the Project Name, and select Add -> "Add Existing Item" from the context menu.
  3. In the "Add Existing Item" dialog box, browse for "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Examples\DotNet\VB\OcrDemo\UI" or "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Examples\DotNet\CS\OcrDemo\UI" and select "OcrRasterImageViewer.vb" or "OcrRasterImageViewer.cs".

    NOTE: You may have to change the actual folder name, if you installed LEADTOOLS to a folder other than the default.

  4. Drag and drop three buttons in Form1. Leave all the buttons names as the default "button14, button15 ...", then change the following properties of button14:
    PropertyValue
    TextDraw Zone
  5. Change the following properties of button15:
    PropertyValue
    TextDraw Page
  6. 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 "\LEAD Technologies\LEADTOOLS 15\Bin\DotNet\Win32 " folder and select the following DLLs:
    • Leadtools.WinForms.dll
    Click the Select button and then press the OK button to add the above DLLs to the application.
  7. 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:

    [Visual Basic]

    
    Imports Leadtools.WinForms
    
    [C#]
    
    using Leadtools.WinForms;
    
  8. Add the following private variables to Form1 class:

    [Visual Basic]

    
    Private WithEvents viewer As OcrRasterImageViewer
    
    [C#]
    
    private OcrDemo.OcrRasterImageViewer viewer;
    
  9. Add the following code at the end of Form_Load procedure:

    [Visual Basic]

    
    ' Initialize the Ocr viewer
    viewer = New OcrRasterImageViewer
    viewer.BackColor = Color.DarkCyan
    viewer.Dock = DockStyle.Fill
    Controls.Add(viewer)
    viewer.InteractiveMode = RasterViewerInteractiveMode.Pan
    
    [C#]
    
    // Initialize the Ocr viewer
    viewer = new OcrDemo.OcrRasterImageViewer();
    viewer.BackColor = Color.DarkCyan;
    viewer.Dock = DockStyle.Fill;
    Controls.Add(viewer);
    viewer.InteractiveMode = RasterViewerInteractiveMode.Pan;
    
  10. Add the following code at button2 control’s click procedure:

    [Visual Basic]

    After the line

    
    Dim rasterImage As RasterImage = codecs.Load("C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\ocr1.tif")
    
    Add the following line
    
    viewer.Image = rasterImage.Clone
    
    [C#]

    In the Block

    
    using (RasterImage rasterImage = codecs.Load(@"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\ocr1.tif"))
    
    Add the following line
    
    viewer.Image = rasterImage.Clone();
    
  11. Add the following code in the beginning of button3 control’s click procedure:

    [Visual Basic]

     
    viewer.DrawPage = False
    viewer.OcrMode = False
    viewer.Image.Dispose()
    viewer.Image = Nothing
    
    [C#]
     
    viewer.DrawPage = false;
    viewer.OcrMode = false;
    viewer.Image.Dispose();
    viewer.Image = null;
    
  12. Add the following code in button14 control’s click procedure:

    [Visual Basic]

    
    Private Sub button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button14.Click
       ' When you call DrawPage, the page zones will not be drawn. 
       Dim zoneOpts As RasterDocumentDrawZoneOptions = rasterDocument.DrawZoneOptions
       zoneOpts.Visible = Not (zoneOpts.Visible)
    End Sub
    
    [C#]
    
    private void button14_Click(object sender, System.EventArgs e)
    {
       // When you call DrawPage, the page zones will not be drawn.
       RasterDocumentDrawZoneOptions zoneOpts = rasterDocument.DrawZoneOptions;
       zoneOpts.Visible = !zoneOpts.Visible;
    }
    
  13. Add the following code in button15 control’s click procedure:

    [Visual Basic]

    
    Private Sub button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button15.Click
       ' Initialize a new Graphics object
       Dim graph As System.Drawing.Graphics = viewer.CreateGraphics()
       
       ' Draw the first page of the RasterDocument object
       rasterDocument.ActivePage = 0
       viewer.RasterDocument = rasterDocument
       viewer.OcrMode = True
       viewer.DrawPage = True
       viewer.Refresh()
    End Sub
    
    [C#]
    
    private void button15_Click(object sender, System.EventArgs e)
    {
       // Initialize a new Graphics object
       System.Drawing.Graphics graph = viewer.CreateGraphics();
       
       // Draw the first page of the RasterDocument object
       rasterDocument.ActivePage = 0;
       viewer.RasterEngine = rasterDocument;
       viewer.OcrMode  = true;
       viewer.DrawPage = true;
       viewer.Refresh();
    }
    
  14. Build, and Run the project to test it.