By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,644 Members | 1,901 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,644 IT Pros & Developers. It's quick & easy.

How to create rubberband effect when drawing line?

P: n/a
Hi All,

In my application I am allowing the user to draw a line. But when the user
clicks the start point and starts moving the mouse there is a series of line
generated. When the mouse is up the final line is drawn.

How to avoid the series of lines being generated during mouse move event?
How to get the rubberband effect when the user moves the mouse?

I tried using the ControlPaint.Reversible line but this does not help
because the mouse cursor and the drawn line does not lie in the same
co-ordinates. There is always an offset. I even tried PointtoScreen and
there is still an offset.

Is there any solution for this?

Can anybody please help. Thanks for your time.

Thanks
Anand Ganesj
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I am relatively new at the C# thing but in C++ what you would do is;

1) Create a memory bitmap that hold the portion of the screen from the
first point to the second point. This bitmap(a) will later be used to
erase the line.
2) Make a copy of the bitmap(a) into another bitmap(b)
3) draw the line into the bitmap
4) copy the bitmap onto the screen.

When the mouse moves, get the new start and end points.
1) Create a new bitmap(b) that holds the screen image for the new points
2) copy the bitmap(a) from above into the new one. - This erases the
first line
3) Make a copy of bitmap(b) into bitamp(a) - to be used to erase
4) draw the line in bitmap(b)
5) copy the bitmap to the screen.

It sounds complicated but it is really about that many lines of code.
The thing is to keep erasing the old line and then draw the new line.
Do it all in memory bitmaps there is no flicker.

In C# you would use the Bitmap class. Everything else would be the
same.

"Anand Ganesh" <an**********@hotmail.com> wrote in
news:uP**************@TK2MSFTNGP12.phx.gbl:
Hi All,

In my application I am allowing the user to draw a line. But when the
user clicks the start point and starts moving the mouse there is a
series of line generated. When the mouse is up the final line is
drawn.

How to avoid the series of lines being generated during mouse move
event? How to get the rubberband effect when the user moves the mouse?

I tried using the ControlPaint.Reversible line but this does not help
because the mouse cursor and the drawn line does not lie in the same
co-ordinates. There is always an offset. I even tried PointtoScreen
and there is still an offset.

Is there any solution for this?

Can anybody please help. Thanks for your time.

Thanks
Anand Ganesj


--
Please remove the jnkmail. from the return address.
Nov 15 '05 #2

P: n/a
hello,
check this link :
http://support.microsoft.com/default...;en-us;Q314945

PeteR.
"Anand Ganesh" <an**********@hotmail.com> schreef in bericht
news:uP**************@TK2MSFTNGP12.phx.gbl...
Hi All,

In my application I am allowing the user to draw a line. But when the user
clicks the start point and starts moving the mouse there is a series of line generated. When the mouse is up the final line is drawn.

How to avoid the series of lines being generated during mouse move event?
How to get the rubberband effect when the user moves the mouse?

I tried using the ControlPaint.Reversible line but this does not help
because the mouse cursor and the drawn line does not lie in the same
co-ordinates. There is always an offset. I even tried PointtoScreen and
there is still an offset.

Is there any solution for this?

Can anybody please help. Thanks for your time.

Thanks
Anand Ganesj

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.