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



graphics
The Graphics object used to paint.
centerPoint
The center point of the Magnifying Glass rectangle
Occurs when the Magnifying Glass crosshair is redrawn.

Syntax

Visual Basic (Declaration) 
Protected Overridable Sub OnPaintCrosshair( _
   ByVal graphics As Graphics, _
   ByVal centerPoint As Point _
) 
Visual Basic (Usage)Copy Code
Dim instance As RasterMagnifyGlass
Dim graphics As Graphics
Dim centerPoint As Point
 
instance.OnPaintCrosshair(graphics, centerPoint)
C# 
protected virtual void OnPaintCrosshair( 
   Graphics graphics,
   Point centerPoint
)
C++/CLI 
protected:
virtual void OnPaintCrosshair( 
   Graphics graphics,
   Point centerPoint
) 

Parameters

graphics
The Graphics object used to paint.
centerPoint
The center point of the Magnifying Glass rectangle

Example

Visual BasicCopy Code
Private Class MyRasterMagnifyGlass : Inherits RasterMagnifyGlass
    Public Sub New()
        Shape = RasterMagnifyGlassShape.Border3D
    End Sub
    Protected Overrides Sub OnPaintBorder(ByVal graphics As Graphics, ByVal centerPoint As Point)
        Dim width As Integer = (Size.Width - 2) \ 2
        Dim height As Integer = (Size.Height - 2) \ 2

        Dim rc As Rectangle = New Rectangle(centerPoint.X - width, centerPoint.Y - height, 2 * width, 2 * height)
        graphics.DrawRectangle(Pens.Blue, rc)
    End Sub

    Protected Overrides Sub OnPaintCrosshair(ByVal graphics As Graphics, ByVal centerPoint As Point)
        Dim width As Integer = (Size.Width - 2) \ 2
        Dim height As Integer = (Size.Height - 2) \ 2
        Dim p1 As Point = New Point(centerPoint.X - width, centerPoint.Y - height)
        Dim p2 As Point = New Point(centerPoint.X + width, centerPoint.Y + height)
        graphics.DrawLine(Pens.Red, p1, p2)

        p1 = New Point(centerPoint.X + width, centerPoint.Y - height)
        p2 = New Point(centerPoint.X - width, centerPoint.Y + height)
        graphics.DrawLine(Pens.Red, p1, p2)
    End Sub
End Class

Private Sub viewer_MagnifyGlassChanged(ByVal sender As Object, ByVal e As EventArgs)
    MessageBox.Show("Custom Magnify Glass being used -- red X for crosshair, blue for border")
End Sub

Public Sub RasterImageViewer_MagnifyGlass(ByVal viewer As RasterImageViewer)
    AddHandler viewer.MagnifyGlassChanged, AddressOf viewer_MagnifyGlassChanged
    viewer.MagnifyGlass = New MyRasterMagnifyGlass()
    viewer.InteractiveMode = RasterViewerInteractiveMode.MagnifyGlass

    RemoveHandler viewer.MagnifyGlassChanged, AddressOf viewer_MagnifyGlassChanged
End Sub
C#Copy Code
class MyRasterMagnifyGlass : RasterMagnifyGlass 

   public MyRasterMagnifyGlass() 
   { 
      Shape = RasterMagnifyGlassShape.Border3D; 
   } 
   protected override void OnPaintBorder(Graphics graphics, Point centerPoint) 
   { 
      int width = (Size.Width - 2) / 2; 
      int height = (Size.Height - 2) / 2; 
 
      Rectangle rc = new Rectangle(centerPoint.X - width, centerPoint.Y - height, 2*width, 2*height); 
      graphics.DrawRectangle(Pens.Blue, rc); 
   } 
 
   protected override void OnPaintCrosshair(Graphics graphics, Point centerPoint) 
   { 
      int width = (Size.Width - 2) / 2; 
      int height = (Size.Height - 2) / 2; 
      Point p1 = new Point(centerPoint.X - width, centerPoint.Y - height); 
      Point p2 = new Point(centerPoint.X + width, centerPoint.Y + height); 
      graphics.DrawLine(Pens.Red, p1, p2); 
 
      p1 = new Point(centerPoint.X + width, centerPoint.Y - height); 
      p2 = new Point(centerPoint.X - width, centerPoint.Y + height); 
      graphics.DrawLine(Pens.Red, p1, p2); 
   } 

 
private void viewer_MagnifyGlassChanged(object sender, EventArgs e) 

   MessageBox.Show("Custom Magnify Glass being used -- red X for crosshair, blue for border"); 

 
public void RasterImageViewer_MagnifyGlass(RasterImageViewer viewer) 

   viewer.MagnifyGlassChanged+= new EventHandler(viewer_MagnifyGlassChanged); 
   viewer.MagnifyGlass = new MyRasterMagnifyGlass(); 
   viewer.InteractiveMode = RasterViewerInteractiveMode.MagnifyGlass; 
 
   viewer.MagnifyGlassChanged -= new EventHandler(viewer_MagnifyGlassChanged); 
}

Remarks

You can override this method in order to paint your own crosshair for the Magnifying Glass. Call the base class implementation for the default behavior.

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