Error processing SSI file
LEADTOOLS Windows Forms (Leadtools.WinForms assembly)

Show in webframe

InteractiveUserRectangle Event






Occurs when the user performs user-defined interactive drawing of a rectangle.
Syntax
[CategoryAttribute("Interactive Mode")]
[DescriptionAttribute("Occurs on interactive mode user rectangle operations.")]
public event EventHandler<RasterViewerRectangleEventArgs> InteractiveUserRectangle
'Declaration
 
<CategoryAttribute("Interactive Mode")>
<DescriptionAttribute("Occurs on interactive mode user rectangle operations.")>
Public Event InteractiveUserRectangle As EventHandler(Of RasterViewerRectangleEventArgs)
'Usage
 
Dim instance As RasterImageViewer
Dim handler As EventHandler(Of RasterViewerRectangleEventArgs)
 
AddHandler instance.InteractiveUserRectangle, handler

            

            
[CategoryAttribute("Interactive Mode")]
[DescriptionAttribute("Occurs on interactive mode user rectangle operations.")]
public:
event EventHandler<RasterViewerRectangleEventArgs^>^ InteractiveUserRectangle
Event Data

The event handler receives an argument of type RasterViewerRectangleEventArgs containing data related to this event. The following RasterViewerRectangleEventArgs properties provide information specific to this event.

PropertyDescription
Cancel (Inherited from Leadtools.WinForms.RasterViewerInteractiveEventArgs)Gets or sets a value indicating whether the interactive mode should be canceled.
Rectangle Returns the current interactive mode rectangle.
Status (Inherited from Leadtools.WinForms.RasterViewerInteractiveEventArgs)Gets the current status of the interactive mode.
Remarks

Only occur when the InteractiveMode property is set to RasterViewerInteractiveMode.UserRectangle.

Use the RasterViewerInteractiveMode.UserRectangle and InteractiveUserRectangle to draw a rectangle on the surface of the viewer. The RasterImageViewer object will handle mouse cursor 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.

Example

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

Copy Code  
Imports Leadtools.WinForms
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Drawing

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

      Dim lrect As LeadRect = New LeadRect(rect.Left, rect.Top, rect.Width, rect.Height)
      image.AddRectangleToRegion(Nothing, lrect, RasterRegionCombineMode.Set)
      Dim cmd As New InvertCommand()
      cmd.Run(image)

      ' Remove the region
      image.MakeRegionEmpty()
   End If
End Sub
using Leadtools.WinForms;
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing.Color;
using Leadtools.Drawing;

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;

      LeadRect ltRect = new LeadRect(rect.Left, rect.Top, rect.Width, rect.Height);
      image.AddRectangleToRegion(null, ltRect, RasterRegionCombineMode.Set);

      InvertCommand cmd = new InvertCommand();
      cmd.Run(image);

      // Remove the region
      image.MakeRegionEmpty();
   }
}
Requirements

Target Platforms

See Also

Reference

RasterImageViewer Class
RasterImageViewer Members

Error processing SSI file