LEADTOOLS WPF and Silverlight (Leadtools.Windows.Controls assembly)

ImagePanViewer Class

Show in webframe
Example 





Members 
Represents a LEADTOOLS image pan control for displaying a scaled view of an image. ImagePanViewer
Object Model
Syntax
Remarks

The ImagePanViewer control is used to display a scaled view of an image, which is also being displayed in the ImageViewer or RasterImageViewer controls at a size that would require scrolling.

ImagePanViewer will maintain the images aspect ratio, a colored pan rectangle will be displayed to indicate the portion of the image currently being displayed in the ImageViewer or RasterImageViewer associated with this pan control.

When a user clicks inside the ImagePanViewer and moves the mouse while holding down the button, the pan rectangle will move with the mouse pointer.

Set the Source property to the ImageViewer or RasterImageViewer object to be panned.

The control draws the pan rectangle using the Stroke as its color, StrokeThickness as the size of the rectangle border in pixels. You can fill the area inside the pan rectangle with InnerBrush and the area outside the pan rectangle with OuterBrush.

Example
Copy Code  
Imports Leadtools.Windows.Controls

Private Class MyWindow1 : Inherits Window
    Public panViewer As ImagePanViewer
    Public viewer As ImageViewer
    Public dockPanel As DockPanel
    Public Sub New(ByVal title As String)
        MyBase.New()
        title = title

        ' Set the size of the window
        Width = 800
        Height = 600

        ' Create the viewer
        viewer = New ImageViewer()
        viewer.Width = 400
        viewer.Height = 400

        ' Load an image
        viewer.Source = New BitmapImage(New Uri(Path.Combine(LEAD_VARS.ImagesDir, "cannon.jpg")))

        panViewer = New ImagePanViewer()
        panViewer.Width = 200
        panViewer.Height = 200
        panViewer.HorizontalAlignment = HorizontalAlignment.Center
        panViewer.VerticalAlignment = VerticalAlignment.Center
        AddHandler panViewer.Pan, AddressOf panViewer_Pan

        dockPanel = New DockPanel()
        Content = dockPanel
        dockPanel.Children.Add(viewer)
        dockPanel.Children.Add(panViewer)
        dockPanel.SetDock(panViewer, Dock.Top)

        panViewer.Stroke = Brushes.Blue
        Dim brush As Brush = New LinearGradientBrush(Colors.Red, Colors.Black, 45)
        panViewer.InnerBrush = New SolidColorBrush(Color.FromArgb(128, 192, 192, 192))
        panViewer.OuterBrush = New SolidColorBrush(Color.FromArgb(128, 200, 192, 192))
        panViewer.Position = New Point(10, 10)
        panViewer.Cursor = Cursors.Hand
        panViewer.Source = viewer
    End Sub

    Private Sub panViewer_Pan(ByVal sender As Object, ByVal e As ImagePanViewerEventArgs)
        Select Case e.Status
            Case ImagePanViewerStatus.Begin, ImagePanViewerStatus.Panning, ImagePanViewerStatus.End
                Title = "Pan Status = " & e.Status.ToString() & " Rectangle =" & e.Rectangle.ToString() & " Cancel = " & e.Cancel.ToString()
                Console.WriteLine(Title)
                Exit Select
        End Select
    End Sub
End Class

Public Sub ImagePanViewer_Source()
    Dim window As MyWindow1 = New MyWindow1("Test_MyImagePanViewer: Writes events to console")
    window.ShowDialog()
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools.Help;
using Leadtools.Windows.Controls;

class MyWindow1 : Window
{
   public ImagePanViewer panViewer;
   public ImageViewer viewer;
   public DockPanel dockPanel;
   public MyWindow1(string title)
      : base()
   {
      Title = title;

      // Set the size of the window
      Width = 800;
      Height = 600;

      // Create the viewer
      viewer = new ImageViewer();
      viewer.Width = 400;
      viewer.Height = 400;

      // Load an image
      viewer.Source = new BitmapImage(new Uri(Path.Combine(LEAD_VARS.ImagesDir, "cannon.jpg")));

      panViewer = new ImagePanViewer();
      panViewer.Width = 200;
      panViewer.Height = 200;
      panViewer.HorizontalAlignment = HorizontalAlignment.Center;
      panViewer.VerticalAlignment = VerticalAlignment.Center;
      panViewer.Pan +=new EventHandler<ImagePanViewerEventArgs>(panViewer_Pan);

      dockPanel = new DockPanel();
      Content = dockPanel;
      dockPanel.Children.Add(viewer);
      dockPanel.Children.Add(panViewer);
      DockPanel.SetDock(panViewer, Dock.Top);

      panViewer.Stroke = Brushes.Blue;
      Brush brush = new LinearGradientBrush(Colors.Red, Colors.Black, 45);
      panViewer.InnerBrush = new SolidColorBrush(Color.FromArgb(128, 192,192,192));
      panViewer.OuterBrush = new SolidColorBrush(Color.FromArgb(128, 200, 192, 192));
      panViewer.Position = new Point(10, 10);
      panViewer.Cursor = Cursors.Hand;
      panViewer.Source = viewer;
   }

   private void panViewer_Pan(object sender, ImagePanViewerEventArgs e)
   {
      switch(e.Status)
      {
         case ImagePanViewerStatus.Begin:
         case ImagePanViewerStatus.Panning:
         case ImagePanViewerStatus.End:
            {
               Title = "Pan Status = " + e.Status.ToString() + " Rectangle =" + e.Rectangle.ToString() + " Cancel = " + e.Cancel.ToString();
               Console.WriteLine(Title);
               break;
            }
      }
   }
}

public void ImagePanViewer_Source()
{
   MyWindow1 window = new MyWindow1("Test_MyImagePanViewer: Writes events to console");
   window.ShowDialog();
}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
using Leadtools.Help;
using Leadtools.Windows.Controls;

class MyWindow1 : ChildWindow
{
   public ImagePanViewer panViewer;
   public ImageViewer viewer;
   public StackPanel stackPanel;
   public MyWindow1(string title)
      : base()
   {
      Title = title;

      // Set the size of the window
      Width = 800;
      Height = 600;

      // Create the viewer
      viewer = new ImageViewer();
      viewer.Width = 400;
      viewer.Height = 400;

      // Load an image
      viewer.Source = new BitmapImage(new Uri(LeadtoolsExamples.Common.ImagesPath.Path + "cannon.jpg"));

      panViewer = new ImagePanViewer();
      panViewer.Width = 200;
      panViewer.Height = 200;
      panViewer.HorizontalAlignment = HorizontalAlignment.Center;
      panViewer.VerticalAlignment = VerticalAlignment.Center;
      panViewer.Pan += new EventHandler<ImagePanViewerEventArgs>(panViewer_Pan);

      stackPanel = new StackPanel();
      Content = stackPanel;
      stackPanel.Children.Add(viewer);
      stackPanel.Children.Add(panViewer);

      panViewer.Stroke = new SolidColorBrush(Colors.Blue);

      GradientStop color1 = new GradientStop();
      color1.Color = Colors.Red;
      GradientStop color2 = new GradientStop();
      color2.Color = Colors.Black;

      GradientStopCollection csc = new GradientStopCollection();
      csc.Add(color1);
      csc.Add(color2);

      Brush brush = new LinearGradientBrush(csc, 45.0);
      panViewer.InnerBrush = new SolidColorBrush(Color.FromArgb(128, 192, 192, 192));
      panViewer.OuterBrush = new SolidColorBrush(Color.FromArgb(128, 200, 192, 192));
      panViewer.Position = new Point(10, 10);
      panViewer.Cursor = Cursors.Hand;
      panViewer.Source = viewer;
   }

   private void panViewer_Pan(object sender, ImagePanViewerEventArgs e)
   {
      switch (e.Status)
      {
         case ImagePanViewerStatus.Begin:
         case ImagePanViewerStatus.Panning:
         case ImagePanViewerStatus.End:
            {
               Title = "Pan Status = " + e.Status.ToString() + " Rectangle =" + e.Rectangle.ToString() + " Cancel = " + e.Cancel.ToString();
               Console.WriteLine(Title);
               break;
            }
      }
   }
}

public void ImagePanViewer_Source()
{
   MyWindow1 window = new MyWindow1("Test_MyImagePanViewer: Writes events to console");
   window.Show();
}
Imports Leadtools.Windows.Controls

Private Class MyWindow1 : Inherits ChildWindow
   Public panViewer As ImagePanViewer
   Public viewer As ImageViewer
   Public stackPanel As StackPanel
   Public Sub New(ByVal title As String)
      MyBase.New()
      Title = title

      ' Set the size of the window
      Width = 800
      Height = 600

      ' Create the viewer
      viewer = New ImageViewer()
      viewer.Width = 400
      viewer.Height = 400

      ' Load an image
      viewer.Source = New BitmapImage(New Uri(LeadtoolsExamples.Common.ImagesPath.Path & "cannon.jpg"))

      panViewer = New ImagePanViewer()
      panViewer.Width = 200
      panViewer.Height = 200
      panViewer.HorizontalAlignment = HorizontalAlignment.Center
      panViewer.VerticalAlignment = VerticalAlignment.Center
      AddHandler panViewer.Pan, AddressOf panViewer_Pan

      stackPanel = New StackPanel()
      Content = stackPanel
      stackPanel.Children.Add(viewer)
      stackPanel.Children.Add(panViewer)

      panViewer.Stroke = New SolidColorBrush(Colors.Blue)

      Dim color1 As GradientStop = New GradientStop()
      color1.Color = Colors.Red
      Dim color2 As GradientStop = New GradientStop()
      color2.Color = Colors.Black

      Dim csc As GradientStopCollection = New GradientStopCollection()
      csc.Add(color1)
      csc.Add(color2)

      Dim brush As Brush = New LinearGradientBrush(csc, 45.0)
      panViewer.InnerBrush = New SolidColorBrush(Color.FromArgb(128, 192, 192, 192))
      panViewer.OuterBrush = New SolidColorBrush(Color.FromArgb(128, 200, 192, 192))
      panViewer.Position = New Point(10, 10)
      panViewer.Cursor = Cursors.Hand
      panViewer.Source = viewer
   End Sub

   Private Sub panViewer_Pan(ByVal sender As Object, ByVal e As ImagePanViewerEventArgs)
      Select Case e.Status
         Case ImagePanViewerStatus.Begin, ImagePanViewerStatus.Panning, ImagePanViewerStatus.End
               Title = "Pan Status = " & e.Status.ToString() & " Rectangle =" & e.Rectangle.ToString() & " Cancel = " & e.Cancel.ToString()
               Console.WriteLine(Title)
               Exit Select
      End Select
   End Sub
End Class

Public Sub ImagePanViewer_Source()
   Dim window As MyWindow1 = New MyWindow1("Test_MyImagePanViewer: Writes events to console")
   window.Show()
End Sub
<Window x:Class="WPFSamples.ImagePanViewer"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Leadtools_Windows_Controls="clr-namespace:Leadtools.Windows.Controls;assembly=Leadtools.Windows.Controls"
    Title="ImagePanViewer" Height="600" Width="800">
  <DockPanel>
    <Leadtools_Windows_Controls:ImagePanViewer
              DockPanel.Dock= "Bottom"
              Width="200" Height="200"
              Source="{Binding ElementName=Viewer}"
              Stroke="Red">
    </Leadtools_Windows_Controls:ImagePanViewer>

    <Leadtools_Windows_Controls:ImageViewer x:Name="Viewer" Source="file:///c:\users\Public\Documents\LEADTOOLS Images\cannon.jpg" Width="400" Height="400"/>
  </DockPanel>
</Window>
Requirements

Target Platforms

See Also

Reference

ImagePanViewer Members
Leadtools.Windows.Controls Namespace

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.