Filed under: General, Programming, .NET — Oliver Sturm @ 7:22 pm - 2 years, 2 months ago
In two previous posts (here and here) I have previously posted about how to draw rubber band selection rectangles similar to what Explorer does. Now a reader contacted me by email and asked for an extension: he wants to have a reverse selection, similar to this picture:
So, no problem of course I started out from the improved version of the first demo and made a few changes – all you have to do is replace the SelectionPanel.OnPaint() method with this:
The result is this (I got rid of my main form drawing routine and inserted a nice background picture instead). Very nice!
Update: As requested, I’m making the complete sample project available. Here’s the download.
Oliver, that is impressive! Can you post the project?
In your example is the selection floating over the entire form or can it be contrained to an image? This idea would be to server as a nice way to highlight an image to be clipped. if you loaded an image on a form using GDI would it be hard to restrict the rubberband to only work within the rectangle boundary of the host image?
How hard would it be to have the rubberband image stay up afte you draw it? Ideally you could guess at your selection and then once drawn be able to move and adjust the frame based on handles. I have read that the ControlPaint class has a DrawGrabHandle() method which creates drag handles but its very lightly documented.
I’ll keep looking around but ideally I’d take your starting code and build the ability to adjust the size of the frame vertically, horizontally and diagonally as well as be able to rotate it. And then once its positioned and adjusted correctly it would be a powerful tool to be able to precisely clip an image.
Thanks!
Rick
Comment by Rick Engle — 13/10/2006 @ 7:59 pm - 2 years, 2 months ago
I just made the download available from the article above (right at the bottom). I’ll look into your other suggestions
Oliver, that is impressive! Can you post the project?
In your example is the selection floating over the entire form or can it be contrained to an image? This idea would be to server as a nice way to highlight an image to be clipped. if you loaded an image on a form using GDI would it be hard to restrict the rubberband to only work within the rectangle boundary of the host image?
How hard would it be to have the rubberband image stay up afte you draw it? Ideally you could guess at your selection and then once drawn be able to move and adjust the frame based on handles. I have read that the ControlPaint class has a DrawGrabHandle() method which creates drag handles but its very lightly documented.
I’ll keep looking around but ideally I’d take your starting code and build the ability to adjust the size of the frame vertically, horizontally and diagonally as well as be able to rotate it. And then once its positioned and adjusted correctly it would be a powerful tool to be able to precisely clip an image.
Thanks!
Rick
Comment by Rick Engle — 13/10/2006 @ 7:59 pm - 2 years, 2 months ago
I just made the download available from the article above (right at the bottom). I’ll look into your other suggestions
Comment by Oliver Sturm — 14/10/2006 @ 5:40 pm - 2 years, 2 months ago