Occurs when the user performs user-defined interactive drawing of a rectangle.
public event EventHandler<RasterViewerRectangleEventArgs> InteractiveUserRectangle
public:
event EventHandler<RasterViewerRectangleEventArgs^>^ InteractiveUserRectangle
public:
event EventHandler<RasterViewerRectangleEventArgs^>^ InteractiveUserRectangle
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.
Property | Description |
---|---|
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. |
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.
This example will use the user-defined rectangle interactive mode to let the user select a rectangle on the image to invert.
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();
}
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document