Rubberband Line 
Author Message
 Rubberband Line

Using VB 4.0;  I have been trying to place a line on a form using the line method i.e.,
line (x1,y1)-(x2,y2).  That is easy enough. However, my need is to allow the
"{*filter*}band" effect as used in drawing  programs whereby a mouse click sets the start
point and then the line visually follows the cursor until the second click sets the end
point.
I prefer the line method as opposed to the line control if possible.
I set the start point in Mouse Down Event which seems to work.
So far, I have tried various codeing in the Mouse Move Event  without success.  Either
the screen fills with multiple lines as the cursor is moved around, or if  I include a
Refresh method in the code all other lines on the screen are erased and the only line
remaining is the {*filter*}band line.

Any help would be appreciated.  Thanks!
Eugene Held



Thu, 18 May 2000 03:00:00 GMT  
 Rubberband Line

Eugene,

I've achieved this effect before by using a shape control with the
BorderStyle set to "Dot".
Set the Top, Left, Height, Width and Visible properties on the MouseDown,
MouseMove and MouseUp events.

It's lame, but it worked!

Questions/comments? Feel free to e-mail me!
Andrew J. Marshall
Elmhurst, IL



Quote:
> Using VB 4.0;  I have been trying to place a line on a form using the
line method i.e.,
> line (x1,y1)-(x2,y2).  That is easy enough. However, my need is to allow
the
> "{*filter*}band" effect as used in drawing  programs whereby a mouse click
sets the start
> point and then the line visually follows the cursor until the second
click sets the end
> point.
> I prefer the line method as opposed to the line control if possible.
> I set the start point in Mouse Down Event which seems to work.
> So far, I have tried various codeing in the Mouse Move Event  without
success.  Either
> the screen fills with multiple lines as the cursor is moved around, or if
 I include a
> Refresh method in the code all other lines on the screen are erased and
the only line
> remaining is the {*filter*}band line.

> Any help would be appreciated.  Thanks!
> Eugene Held




Fri, 19 May 2000 03:00:00 GMT  
 Rubberband Line

Quote:

>Using VB 4.0;  I have been trying to place a line on a form using the line method i.e.,
>line (x1,y1)-(x2,y2).  That is easy enough. However, my need is to allow the
>"{*filter*}band" effect as used in drawing  programs whereby a mouse click sets the start
>point and then the line visually follows the cursor until the second click sets the end
>point.
>I prefer the line method as opposed to the line control if possible.

There's a demo for {*filter*}banding in the KB:

        "How to Create {*filter*}-Band Lines/Boxes in Visual Basic"
        Article ID: Q71488
        http:://www.microsoft.com/kb/

However, it works slightly different than you describe: you can drag the
second corner as long as the mouse is down.

Implementing according to your description might problems, especially if
the second click isn't on your form, maybe not even on your application.

This might be resolved by using a SetCapture() API call as soon as your
form is clicked. Then, all mousemove events will be sent to your form.

        dummy = SetCapture(me.hWnd)

Note that VB uses this API function internally, as soon as the mouse
goes down. This will interfere with your call, as it will releases the
mouse as soon as the mousebutton goes up. Therefore, you'll need to use
this call in the mouseup event.

For the same reason, you probably won't need to call ReleaseCapture() on
the second click.

HTH,
Bart.



Fri, 19 May 2000 03:00:00 GMT  
 Rubberband Line

eugene

The effect of {*filter*}banding is achieved by drawing a line initially and
then, on a mouse movement, erasing the first line and drawing a second
line and so on.

You should draw all lines with the exclusive or (vbXorPen) DrawMode and
then draw it again identically to erase it.

Regards
{*filter*}



Fri, 19 May 2000 03:00:00 GMT  
 Rubberband Line

Quote:

>Using VB 4.0;  I have been trying to place a line on a form using the line
> method i.e.,
>line (x1,y1)-(x2,y2).  That is easy enough. However, my need is to allow the
>"{*filter*}band" effect as used in drawing  programs whereby a mouse click sets the
> start
>point and then the line visually follows the cursor until the second click sets
> the end
>point.
>I prefer the line method as opposed to the line control if possible.
>I set the start point in Mouse Down Event which seems to work.
>So far, I have tried various codeing in the Mouse Move Event  without success.
> Either
>the screen fills with multiple lines as the cursor is moved around, or if  I
> include a
>Refresh method in the code all other lines on the screen are erased and the
> only line
>remaining is the {*filter*}band line.

>Any help would be appreciated.  Thanks!
>Eugene Held


What you will want to do is draw the line by inverting the pixels as the user
moves the {*filter*}band line. By inverting the first time you can restore the
original colors by inverting again. In other words, invert when drawing the
line then, in the MouseMove event invert the original line and then invert the
new line. Once the user is done you can draw the final line in the color of
your choice.

Try setting the DrawMode of the parent to vbInvert during the {*filter*}banding
and change it back to vbCopyPen when drawing the final line.

This is off the top of my head so you may have to experiment a bit.

-Stu



Fri, 19 May 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Rubberband Line with ScrollBar

2. Rubberband Arc or Rubberband Curve

3. RubberBand UserControls

4. Rubberband Rectangle in ACCESS-Form via WinApi

5. Drawing rubberband OVER controls

6. RubberBand TextBox

7. RubberBand TextBox

8. ?! Rubberband always at the background ?!

9. Continuing a line of code on the next line

10. Using Line Input to go back a line

11. Select two lines, return as one line

12. reading mail message body line by line

 

 
Powered by phpBB® Forum Software