Leadtools.WinForms Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.8.31
CenterAtPoint Method
See Also  Example
Leadtools.WinForms Namespace > RasterImageViewer Class : CenterAtPoint Method




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

Syntax

Visual Basic (Declaration) 
Public Overridable Sub CenterAtPoint( _
   ByVal pt As Point _
) 
Visual Basic (Usage)Copy Code
Dim instance As RasterImageViewer
Dim pt As Point
 
instance.CenterAtPoint(pt)
C# 
public virtual void CenterAtPoint( 
   Point pt
)
Managed Extensions for 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
Sub ZoomAndCenter(ByVal viewer As RasterImageViewer, 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 Rectangle = Rectangle.Intersect(viewer.PhysicalViewRectangle, viewer.ClientRectangle)
      ' Get the center of what you see in physical coordinates
      Dim center As New PointF(rc.Left + rc.Width \ 2, rc.Top + rc.Height \ 2)
      Dim t As New Transformer(viewer.Transform)
      ' Get the center of what you see in logical coordinates
      center = t.PointToLogical(center)

      ' Set the new scale factor
      viewer.ScaleFactor = scaleFactor

      ' Bring the original center into the view center

      t = New Transformer(viewer.Transform)
      ' Get the center of what you saw before the zoom in physical coordinates
      center = t.PointToPhysical(center)
      ' Bring the old center into the center of the view
      viewer.CenterAtPoint(Point.Round(center))
   End If
End Sub
C#Copy Code
void ZoomAndCenter(RasterImageViewer 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 
      Rectangle rc = Rectangle.Intersect(viewer.PhysicalViewRectangle, viewer.ClientRectangle); 
      // Get the center of what you see in physical coordinates 
      PointF center = new PointF(rc.Left + rc.Width / 2, rc.Top + rc.Height / 2); 
      Transformer t = new Transformer(viewer.Transform); 
      // Get the center of what you see in logical coordinates 
      center = t.PointToLogical(center); 
 
      // Set the new scale factor 
      viewer.ScaleFactor = scaleFactor; 
 
      // Bring the original center into the view center 
 
      t = new Transformer(viewer.Transform); 
      // Get the center of what you saw before the zoom in physical coordinates 
      center = t.PointToPhysical(center); 
      // Bring the old center into the center of the view 
      viewer.CenterAtPoint(Point.Round(center)); 
   } 
}

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also