In this tutorial, you will configure a C# or VB.NET project for a Windows Forms application and use ImageGear .NET capabilities. You will also learn how to load a document, then view, zoom, and rotate it.
This tutorial also uses the ImageGear .NET GUI components. Make sure you've followed the steps to Install GUI Components.
The following tutorial refers specifically to 64-bit installations; for 32-bit installations:
- Your project should already be set to compile to target Debug and x86, and you should have the directory: $YOURLOCALPROJ\bin\x86\Debug\.
- Throughout these instructions, replace x64 with x86.
- The 32-bit ImageGear binaries are found in $INSTALLDIR\Bin\x86
Using Visual Studio 2015 or later:
- Create a new "Windows Forms Application" project, using C# or VB.NET and name the project: IG_Tutorial_WinForms.
- If you installed IG NET 64-bit, using the Configuration Manager, create a new project platform (if you don’t have one already) for x64. Make sure your project is set to compile targeting Debug and x64. Make sure you now have $YOURLOCALPROJ\bin\x64\Debug\, and if it is not there, create it.
- Add references and required resources into your projects in one of the following ways:
- Recommended: use our NuGet Packages. For this project, you need the following packages:
Accusoft.ImageGear.WinForms.nupkg (https://www.nuget.org/packages/Accusoft.ImageGear.WinForms/)
- Manually:
- Copy all files (and folders) inside $INSTALLDIR\Bin\x64 to your local output bin directory in your project (i.e., $YOURLOCALPROJ\bin\x64\Debug\ ).
- Add the following references to your project from $YOURLOCALPROJ\bin\x64\Debug\:
- ImageGear.Core.dll
- ImageGear.Evaluation.dll
- ImageGear.Formats.Common.dll
- ImageGear.Presentation.dll
- ImageGear.Windows.Forms.dll
Your output target directory should be set to $YOURLOCALPROJ\bin\x64\Debug\
- Next, you will add some pertinent controls to your form. For this tutorial, keep the default names for the controls:
- First, create a menu on the form. From the Windows Forms toolbox, drag a MenuStrip control onto the form:
- Create three MenuItems called File, View, and Processing.
- Under the File menu, add Load Page
- Under the View menu, add Zoom In and Zoom Out.
- Under the Processing menu, add Rotate 90.
- Double-click each added menu item to create a Click Event Handler.
- Second, also from the toolbox, drag the ImGearPageView control onto the form. This control will be used to display the document loaded. Set the Dock (in the Layout group) property of the imGearPageView1 control to Fill. This will cause the control to resize as the form resizes.
- At this point your project is ready for some code. The following code can be used to load a document, view it using an ImGearPageView control, zoom in/zoom out on it, and rotate it. In the next section, we will go over some areas of this sample code in more detail.
Now, we'll take a closer look at each section of the code:
- First, add the ImGearEvaluationManager.Initialize() call if you are evaluating the product. You also need to initialize common formats.
- Next, load and display a document:
- Execute the Zoom In operation:
Similarly, you can perform Zoom Out by modifying the multiplier of the Horizontal and Vertical values as (1/1.25). See the zoomOutToolStripMenuItem_Click function in the code example in step 5 (above).
- Finally, rotate the page displayed:
Notice that for performing 180 and 270 degree rotations, you can simply change the second parameter of the Rotate method to ImGearRotationValues.VALUE_180 and ImGearRotationValues.VALUE_270, respectively.