LEADTOOLS WPF and Silverlight (Leadtools.Windows.Controls assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.30
ImagePanViewer Class
See Also  Members  
Leadtools.Windows.Controls Namespace : ImagePanViewer Class



Represents a LEADTOOLS image pan control for displaying a scaled view of an image. Supported in Silverlight, Windows Phone 7 ImagePanViewer

Object Model

ImagePanViewer ClassImageViewer Class

Syntax

Visual Basic (Declaration) 
Public Class ImagePanViewer 
   Inherits System.Windows.Controls.UserControl
   Implements ISupportInitializeIFrameworkInputElementIInputElementIAddChildIComponentConnectorIAnimatable 
Visual Basic (Usage)Copy Code
Dim instance As ImagePanViewer

Example

Visual BasicCopy Code
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
C#Copy Code
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";
}
SilverlightCSharpCopy Code
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();
}
SilverlightVBCopy Code
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
XAMLCopy Code
<Window x:Class="WPFSamples.ImagePanViewer" Title="ImagePanViewer" Height="600" Width="800" 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">
  <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>

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.

Inheritance Hierarchy

System.Object
   System.Windows.Threading.DispatcherObject
      System.Windows.DependencyObject
         System.Windows.Media.Visual
            System.Windows.UIElement
               System.Windows.FrameworkElement
                  System.Windows.Controls.Control
                     System.Windows.Controls.ContentControl
                        System.Windows.Controls.UserControl
                           Leadtools.Windows.Controls.ImagePanViewer

Requirements

Target Platforms: Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also