LEAD Technologies, Inc

Using a PanWindow

Take the following steps to start a project and to add some code that uses a PanWindow:
  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" or "Visual Basic Projects" in the Projects Type List, and choose "Windows Application " in the Templates List.
  4. Type the project name as "Using a PanWindow" in the Project Name field, and then click OK. If desired, type a new location for your project or select a directory using the Browse button, and then click OK .
  5. 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 the "<LEADTOOLS_INSTALLDIR>\Bin\DotNet\Win32 " folder and select the following DLLs:
    • Leadtools.dll
    • Leadtools.Codecs.dll
    • Leadtools.Codecs.Cmp.dll
    • Leadtools.WinForms.dll
    Click the Select button and then press the OK button to add the above DLLs to the application.
  6. Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and Drag and drop an instance of RasterImageViewer to the form. If you do not have RasterImageViewer in your toolbox, select Tools->Add Remove Toolbox Items from the menu. Click Browse and then select Leadtools.WinForms.DLL from the "\LEADTOOLS 17.5\Bin\DotNet\Win32" folder, click Open, and then click OK.
  7. Change the following properties:
    Property Value
    Dock Fill
  8. 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
                 Imports Leadtools.Codecs
                 Imports Leadtools.WinForms            
                 
    
    [C#]
                 using Leadtools;
                 using Leadtools.Codecs;
                 using Leadtools.WinForms; 
                 
    
  9. Add an event handler to the Form1 Load event and add the following code:

    [Visual Basic]
                 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                    ' load an image into the viewer
                    Dim codecs As New RasterCodecs()
                    rasterImageViewer1.Image = codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\Image2.cmp")
                    
                    ' Create an instance of Form2
                    Dim form As New Form2
                    Form.Show()
                    
                    ' Set the attribute of the pan viewer
                    Form.PanViewer.BackColor = Color.Bisque
                    form.PanViewer.Viewer = RasterImageViewer1
                    Form.PanViewer.BorderStyle = BorderStyle.None
                    Form.PanViewer.RectangleColor = Color.Blue
                    Form.PanViewer.ImageColor = Color.FromArgb(128, 0, 0, 0)
                    Form.PanViewer.Cursor = Cursors.Hand
                 End Sub
                 
    
    [C#]
                 private void Form1_Load(object sender, System.EventArgs e)
                 {
                    // load an image into the viewer
                    RasterCodecs codecs = new RasterCodecs();
                    rasterImageViewer1.Image = codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\Image2.cmp");
                    
                    // Create an instance of Form2
                    Form2 form = new Form2();
                    form.Show();
                    
                    // Set the attribute of the pan viewer
                    form.PanViewer.BackColor = Color.Bisque;
                    form.PanViewer.Viewer = rasterImageViewer1;
                    form.PanViewer.BorderStyle = BorderStyle.None;
                    form.PanViewer.RectangleColor = Color.Blue;
                    form.PanViewer.ImageColor = Color.FromArgb(128, 0, 0, 0);
                    form.PanViewer.Cursor = Cursors.Hand;
                 }
                 
    
  10. Select Project->Add Windows Forms and add a new Form to the project. Switch to Form2 code view (Right click Form2 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;
                 
    
  11. Add an event handler to the Form2 Load event and code it as follows:

    [Visual Basic]
                 Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                    myPanViewer = New RasterImagePanViewer
                    myPanViewer.Dock = DockStyle.Fill
                    Controls.Add(myPanViewer)
                    myPanViewer.BringToFront()
                 End Sub  
                 
    
    [C#]
                 private void Form2_Load(object sender, System.EventArgs e)
                 {
                    panViewer = new RasterImagePanViewer();
                    panViewer.Dock = DockStyle.Fill;
                    Controls.Add(panViewer);
                    panViewer.BringToFront();
                 }
                 
    
  12. Add the following code to class Form2: [Visual Basic]
                 Private myPanViewer As RasterImagePanViewer
                
                 Public ReadOnly Property PanViewer() As RasterImagePanViewer
                    Get
                       Return myPanViewer
                    End Get
                 End Property
                 
    
    [C#]
                 private RasterImagePanViewer panViewer;
                 public RasterImagePanViewer PanViewer
                 {
                    get
                    {
                       return panViewer;
                    }
                 }
                 
    
  13. Build, and Run the program to test it.

 

 


Products | Support | Contact Us | Copyright Notices

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