InteractiveUserRectangle Event

Summary

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

Syntax

C#
C++/CLI
C++
public event EventHandler<RasterViewerRectangleEventArgs> InteractiveUserRectangle 
public: 
event EventHandler<RasterViewerRectangleEventArgs^>^ InteractiveUserRectangle 
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.

C#
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

Help Version 22.0.2023.2.9
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.WinForms Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.