Take the following steps to start a project and to add some code
that demonstrates how to draw pages and zones:
Start with the program you created in Working with Recognition Results. In the "Solution Explorer" window, right-click on the Project Name, and select Add -> "Add Existing Item" from the context menu. 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.
Drag and drop three buttons in Form1. Leave all the buttons names as the default "button14, button15 ...", then change the following properties of button14: Property Value Text Draw Zone Change the following properties of button15: Property Value Text Draw Page 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
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]
[C#]Imports Leadtools.WinForms
using Leadtools.WinForms;
Add the following private variables to Form1 class: [Visual Basic]
[C#]Private WithEvents viewer As OcrRasterImageViewer
private OcrDemo.OcrRasterImageViewer viewer;
Add the following code at the end of Form_Load procedure: [Visual Basic]
[C#]' Initialize the Ocr viewer viewer = New OcrRasterImageViewer viewer.BackColor = Color.DarkCyan viewer.Dock = DockStyle.Fill Controls.Add(viewer) viewer.InteractiveMode = RasterViewerInteractiveMode.Pan
// Initialize the Ocr viewer viewer = new OcrDemo.OcrRasterImageViewer(); viewer.BackColor = Color.DarkCyan; viewer.Dock = DockStyle.Fill; Controls.Add(viewer); viewer.InteractiveMode = RasterViewerInteractiveMode.Pan;
Add the following code at button2 control’s click procedure: [Visual Basic]
After the line
Add the following lineDim rasterImage As RasterImage = codecs.Load("C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\ocr1.tif")
[C#]viewer.Image = rasterImage.Clone
In the Block
Add the following lineusing (RasterImage rasterImage = codecs.Load(@"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\ocr1.tif"))
viewer.Image = rasterImage.Clone();
Add the following code in the beginning of button3 control’s click procedure: [Visual Basic]
[C#]viewer.DrawPage = False viewer.OcrMode = False viewer.Image.Dispose() viewer.Image = Nothing
viewer.DrawPage = false; viewer.OcrMode = false; viewer.Image.Dispose(); viewer.Image = null;
Add the following code in button14 control’s click procedure: [Visual Basic]
[C#]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
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; }
Add the following code in button15 control’s click procedure: [Visual Basic]
[C#]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
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(); }
Build, and Run the project to test it.