Select, Resize and Move a Rectangle on an Image using Mouse Events.

This demo shows how to use the mouse events in csXImage to enable a user to select a rectangle on an image using the mouse. The rectangle can then be resized or moved, again using the mouse. A screenshot from the demo is shown below:

C# example to select an area on an image

There is a method called "MouseSelectRectangle" provided in csXImage which can give some of the functionality shown in this demo with a single line of code. However, it has some limitations, for example, it uses a crosshair cursor while selecting the rectangle, and there is no possibility to customise this to use a different cursor if desired. This demo shows how to provide this functionality and more using mouse events, with the programmer fully able to customise the behaviour of the application.

The drawing of a rectangle uses the "rubber-banding" technique, where one corner of the rectangle is first selected by a mouse click downwards, then the rectangle is continually redrawn until the mouse button is released to position the opposite corner of the rectangle. If you are not familiar with this technique, click here to see a much simpler demonstration, in which a single straight line is drawn.

This demo can be downloaded from the link below.

To run this demo you need the csXImage trial ocx control installed on your system as well as MS Visual Studio.NET. The trial control and the example files are available below:

Download the trial csXImage control - csXImageTrial.exe (1.8 MB)

The demo C# project - SelectRectDemoCSharp.zip (197 KB)