Results 1 to 5 of 5

Thread: Drawing a Zoom Rectangle... [RESOLVED]

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2002
    Location
    Two places at once
    Posts
    33

    Question 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.

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    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.

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2002
    Location
    Two places at once
    Posts
    33
    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.

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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.

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2002
    Location
    Two places at once
    Posts
    33
    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
  •  



Click Here to Expand Forum to Full Width