tags:

views:

1957

answers:

5

I'm trying to write a very simple photo editor using C# 2008 or QT4.

How to make a resizeable rectangle selection tool like the photoshop did?

+5  A: 

If you are talking about the "classic" "rubber band" type of selection rectangle, check out How to draw a rubber band rectangle or a focus rectangle in Visual C#.

dommer
+2  A: 

I don't know the specific calls, but the idea is this:

You want to draw a transparent rectangle with an opaque or dotted border. The rectangle appears when the mouse button is clicked. While the button is held, the dimension of the rectangle will change as the mouse moves, with the top-left point at the position where the button was clicked and the bottom-right following the mouse as it moves. Releasing the button causes the rectangle to fix its position over the selection area.

You should be able to figure out the particulars from a resource on the C# Drawing namespace.

Dave Swersky
+1  A: 

WPF Code Example: http://www.codeproject.com/KB/WPF/wpfmarchingants.aspx?display=Print

This one is a bit more complicated because it involves image cropping, but if you scroll down to the selection rectangle, you can see the basic formulas for calculating the rectangle: http://69.10.233.10/KB/WPF/ImageCropper.aspx

Lastly, another one using GDI: http://codelog.blogial.com/2008/10/31/rubber-band-selection-rectangle-in-c/

If you provide more specifics, I'm sure we can help you out more.

daub815
+2  A: 

Qt has a class for that:

http://doc.trolltech.com/4.5-snapshot/qrubberband.html