|
-
Jan 12th, 2004, 10:40 AM
#1
Thread Starter
Member
Drawing a Zoom Rectangle... [RESOLVED]
Maybe I'm just daft, but I've been wrangling with this for a while now. The solution is probably blindingly obvious. 
I've got a program that draws a rather large and detailed graph on the screen. I'd like users to be able to select a zoom function, and then drag a zoom rectangle around the area they'd like to zoom into. Since the .NET architecture did away with useful things like VB's shape controls, I'm at somewhat of a loss as to how this could be accomplished.
I already have the code for capturing the start/stop points for the rectangle and for the zooming; I just need the visual cue to let the user know that their clicking-and-dragging isn't being ignored.
Any help would be appreciated. Thanks in advance.
Last edited by smiley_dood; Jan 23rd, 2004 at 04:33 PM.
-
Jan 13th, 2004, 03:55 AM
#2
The usual method is to draw the lines of the rectangle using XOR.
I'm not sure how to do it in .net but in VB 6 all you had to do was set some properties of the picturebox to XOR (I think it was the Drawmode property) and then draw the lines.
Drawing a line this way will show a line, drawing that same line again will revert the pixels to their original color so you get a good dragging effect without ruining the underlying image.
when the mouse moves:
(this is pseudocode, it won't run)...
DrawOldRect() 'hides last rectangle
DrawNewRect((x,y,x1,y1) 'shows new one
OldRect = NewRect 'both probably static or global
I don't live here any more.
-
Jan 13th, 2004, 11:36 AM
#3
Thread Starter
Member
That'll work, I guess, though with that method, the resulting color will always be some kind of inverse of the underlying graph. I'd rather have control over the exact border color.
-
Jan 18th, 2004, 06:57 AM
#4
IMHO
Personally, I'd rather have a program that doesn't waste CPU power with making a drag rect look nice, but if it is pivotal to the workings of your app then there are a couple of methods that spring to mind.
1. Keep an array of the pixel colours that are to be overwritten (if the rect is 10 x 10 then you'd need 36 elements). Re-insert them when the rect has moved.
2. Copy the lines to a bitmap in memory.
I'd try the first one because it uses less ram.
I don't live here any more.
-
Jan 23rd, 2004, 04:32 PM
#5
Thread Starter
Member
Finally found what I was looking for: the BackgroundImage property. Instead of drawing the graph on the PictureBox's Image, I'll draw it onto the PictureBox's BackgroundImage. The Image can then be used for a custom drawn selection rectangle. Whenever the mouse moves, the Image can be cleared with a transparent color, and the rectangle can be redrawn.
Knew it was simple...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|