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



Occurs when the user performs user-defined interactive drawing of a rectangle.

Syntax

Visual Basic (Declaration) 
<DescriptionAttribute("Occurs on interactive mode user rectangle operations.")>
<CategoryAttribute("Interactive Mode")>
Public Event InteractiveUserRectangle() As EventHandler(Of RasterViewerRectangleEventArgs)
Visual Basic (Usage)Copy Code
Dim instance As RasterImageViewer
Dim handler As EventHandler(Of RasterViewerRectangleEventArgs)
 
AddHandler instance.InteractiveUserRectangle, handler
C# 
[DescriptionAttribute("Occurs on interactive mode user rectangle operations.")]
[CategoryAttribute("Interactive Mode")]
public event EventHandler<RasterViewerRectangleEventArgs> InteractiveUserRectangle()
C++/CLI 
[DescriptionAttribute("Occurs on interactive mode user rectangle operations.")]
[CategoryAttribute("Interactive Mode")]
public:
event EventHandler<RasterViewerRectangleEventArgs>^ InteractiveUserRectangle();

Example

This example will use the user-defined rectangle interactive mode to let the user select a rectangle on the image to invert.

Visual BasicCopy Code
Public Sub InteractiveUserRectangleExample(ByVal viewer As RasterImageViewer)
   ' Set the interactive mode of the viewer to user-defined rectangle
   viewer.InteractiveMode = RasterViewerInteractiveMode.UserRectangle
   ' Subscribe to the InteractiveUserRectangle event to know when the user has finished drawing a new rectangle
   AddHandler viewer.InteractiveUserRectangle, AddressOf viewer_InteractiveUserRectangle
End Sub

Private Sub viewer_InteractiveUserRectangle(ByVal sender As Object, ByVal e As RasterViewerRectangleEventArgs)
   ' Check the status of the event
   If (e.Status = RasterViewerInteractiveStatus.End AndAlso Not e.Cancel) Then
      ' The user has finished drawing a new rectangle (and the operation has not been canceled)

      ' Get the rectangle and convert it to image coordinates (with view-perspective)
      Dim viewer As RasterImageViewer = CType(sender, RasterImageViewer)
      Dim rect As Rectangle = e.Rectangle

      ' The user rectangle might have negative width or height (if the user starts the drawing from
      ' bottom-left corner for example), check for that
      If (rect.Left > rect.Right) Then
         rect = Rectangle.FromLTRB(rect.Right, rect.Top, rect.Left, rect.Bottom)
      End If
      If (rect.Top > rect.Bottom) Then
         rect = Rectangle.FromLTRB(rect.Left, rect.Bottom, rect.Right, rect.Top)
      End If

      ' Account for the view perspective of the image
      rect = viewer.ViewerToImageRectangle(rect, True)

      ' Set this as the region and invert the colors
      Dim image As RasterImage = viewer.Image

      image.AddRectangleToRegion(Nothing, rect, RasterRegionCombineMode.Set)
      Dim cmd As New InvertCommand()
      cmd.Run(image)

      ' Remove the region
      image.MakeRegionEmpty()
   End If
End Sub
C#Copy Code
public void InteractiveUserRectangleExample(RasterImageViewer viewer) 

   // Set the interactive mode of the viewer to user-defined rectangle 
   viewer.InteractiveMode = RasterViewerInteractiveMode.UserRectangle; 
   // Subscribe to the InteractiveUserRectangle event to know when the user has finished drawing a new rectangle 
   viewer.InteractiveUserRectangle += new EventHandler<RasterViewerRectangleEventArgs>(viewer_InteractiveUserRectangle); 

 
private void viewer_InteractiveUserRectangle(object sender, RasterViewerRectangleEventArgs e) 

   // Check the status of the event 
   if(e.Status == RasterViewerInteractiveStatus.End && !e.Cancel) 
   { 
      // The user has finished drawing a new rectangle (and the operation has not been canceled) 
 
      // Get the rectangle and convert it to image coordinates (with view-perspective) 
      RasterImageViewer viewer = sender as RasterImageViewer; 
      Rectangle rect = e.Rectangle; 
 
      // The user rectangle might have negative width or height (if the user starts the drawing from 
      // bottom-left corner for example), check for that 
      if(rect.Left > rect.Right) 
         rect = Rectangle.FromLTRB(rect.Right, rect.Top, rect.Left, rect.Bottom); 
      if(rect.Top > rect.Bottom) 
         rect = Rectangle.FromLTRB(rect.Left, rect.Bottom, rect.Right, rect.Top); 
 
      // Account for the view perspective of the image 
      rect = viewer.ViewerToImageRectangle(rect, true); 
 
      // Set this as the region and invert the colors 
      RasterImage image = viewer.Image; 
 
      image.AddRectangleToRegion(null, rect, RasterRegionCombineMode.Set); 
      InvertCommand cmd = new InvertCommand(); 
      cmd.Run(image); 
 
      // Remove the region 
      image.MakeRegionEmpty(); 
   } 
}

Remarks

Only occur when the RasterImageViewer.InteractiveMode property is set to RasterViewerInteractiveMode.UserMode.

Use the RasterViewerInteractiveMode.UserMode and InteractiveUserRectangle to draw a rectangle on the surface of the viewer. The RasterImageViewer object will handle mouse mouse down and up events, mouse movement, canceling (through the ESC key or when the control loses the focus) and clipping.

The InteractiveUserRectangle event will occur everytime the user moves the mouse or clicks any of the buttons with the corresponding data in the RasterViewerRectangleEventArgs of the event.

You can use the user-defined rectangle interactive mode to perform additional interactive operations on the viewer not handled by any of the pre-defined RasterViewerInteractiveMode.

You can use the ViewerToImageRectangle and ImageToViewerRectangle methods to convert a rectangle between image and viewer coordinates.

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