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



pt
The point at which to center the image display, in client coordinates.
pt
The point at which to center the image display, in client coordinates.
Centers the image display at the specified point. Supported in Silverlight, Windows Phone 7

Syntax

Visual Basic (Declaration) 
Public Overridable Sub CenterAtPoint( _
   ByVal pt As Point _
) 
Visual Basic (Usage)Copy Code
Dim instance As ImageViewer
Dim pt As Point
 
instance.CenterAtPoint(pt)
C# 
public virtual void CenterAtPoint( 
   Point pt
)
C++/CLI 
public:
virtual void CenterAtPoint( 
   Point pt
) 

Parameters

pt
The point at which to center the image display, in client coordinates.

Example

This example shows a method to change the viewer scale factor (zoom) while keeping the viewer centered.

Visual BasicCopy Code
Private Sub ZoomAndCenter(ByVal viewer As ImageViewer, ByVal scaleFactor As Double)
    ' Minimum and maximum scale factors allowed (change if you have to)
    Const minimumScaleFactor As Double = 0.05
    Const maximumScaleFactor As Double = 11
    ' Normalize the scale factor based on min and max
    scaleFactor = Math.Max(minimumScaleFactor, Math.Min(maximumScaleFactor, scaleFactor))

    ' Check if we need to change the scale factor for the viewer
    If viewer.ScaleFactor <> scaleFactor Then
        ' Get the current center in logical units
        ' We will use this point later to re-center the viewer

        ' Get what you see in physical coordinates
        Dim rc As Rect = Rect.Intersect(New Rect(0, 0, viewer.Width, viewer.Height), New Rect(viewer.PhysicalSize))

        ' Get the center of what you see in physical coordinates
        Dim center As Point = New Point(rc.Left + rc.Width / 2, rc.Top + rc.Height / 2)

        ' Set the new scale factor
        viewer.ScaleFactor = scaleFactor

        ' Bring the old center into the center of the view
        viewer.CenterAtPoint(center)
    End If
End Sub
C#Copy Code
void ZoomAndCenter(ImageViewer viewer, double scaleFactor)
{
   // Minimum and maximum scale factors allowed (change if you have to)
   const double minimumScaleFactor = 0.05;
   const double maximumScaleFactor = 11;
   // Normalize the scale factor based on min and max
   scaleFactor = Math.Max(minimumScaleFactor, Math.Min(maximumScaleFactor, scaleFactor));

   // Check if we need to change the scale factor for the viewer
   if(viewer.ScaleFactor != scaleFactor)
   {
      // Get the current center in logical units
      // We will use this point later to re-center the viewer

      // Get what you see in physical coordinates
      Rect rc = Rect.Intersect(new Rect(0, 0, viewer.Width, viewer.Height), new Rect(viewer.PhysicalSize));

      // Get the center of what you see in physical coordinates
      Point center = new Point(rc.Left + rc.Width / 2, rc.Top + rc.Height / 2);

      // Set the new scale factor
      viewer.ScaleFactor = scaleFactor;

      // Bring the old center into the center of the view
      viewer.CenterAtPoint(center);
   }
}
SilverlightCSharpCopy Code
void ZoomAndCenter(ImageViewer viewer, double scaleFactor)
{
   // Minimum and maximum scale factors allowed (change if you have to)
   const double minimumScaleFactor = 0.05;
   const double maximumScaleFactor = 11;
   // Normalize the scale factor based on min and max
   scaleFactor = Math.Max(minimumScaleFactor, Math.Min(maximumScaleFactor, scaleFactor));

   // Check if we need to change the scale factor for the viewer
   if(viewer.ScaleFactor != scaleFactor)
   {
      // Get the current center in logical units
      // We will use this point later to re-center the viewer

      // Get what you see in physical coordinates
      LeadRect rc = LeadRect.Intersect(new LeadRect(0, 0, (int)viewer.Width, (int)viewer.Height), new LeadRect(0, 0, (int)viewer.PhysicalSize.Width, (int)viewer.PhysicalSize.Height));

      // Get the center of what you see in physical coordinates
      Point center = new Point(rc.Left + rc.Width / 2, rc.Top + rc.Height / 2);

      // Set the new scale factor
      viewer.ScaleFactor = scaleFactor;

      // Bring the old center into the center of the view
      viewer.CenterAtPoint(center);
   }
}
SilverlightVBCopy Code
Private Sub ZoomAndCenter(ByVal viewer As ImageViewer, ByVal scaleFactor As Double)
   ' Minimum and maximum scale factors allowed (change if you have to)
   Const minimumScaleFactor As Double = 0.05
   Const maximumScaleFactor As Double = 11
   ' Normalize the scale factor based on min and max
   scaleFactor = Math.Max(minimumScaleFactor, Math.Min(maximumScaleFactor, scaleFactor))

   ' Check if we need to change the scale factor for the viewer
   If viewer.ScaleFactor <> scaleFactor Then
      ' Get the current center in logical units
      ' We will use this point later to re-center the viewer

      ' Get what you see in physical coordinates
      Dim rc As LeadRect = LeadRect.Intersect(New LeadRect(0, 0, CInt(viewer.Width), CInt(viewer.Height)), New LeadRect(0, 0, CInt(viewer.PhysicalSize.Width), CInt(viewer.PhysicalSize.Height)))

      ' Get the center of what you see in physical coordinates
      Dim center As Point = New Point(rc.Left + rc.Width / 2, rc.Top + rc.Height / 2)

      ' Set the new scale factor
      viewer.ScaleFactor = scaleFactor

      ' Bring the old center into the center of the view
      viewer.CenterAtPoint(center)
   End If
End Sub

Remarks

The control will position the scrollbars according to user cursor moves, therefore, this method is only functional if the control has visible scrollbars (SizeMode is SizeMode.Normal or SizeMode.FitWidth and the view port is less than the image size).

The control will call this method during InteractiveMode.Pan.

Requirements

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

See Also