473,378 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to create rubberband effect when drawing line?

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
2 11239
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
3
by: James Proctor | last post by:
Hi there, im brand new to ASP. Ive done loads of VB coding and one of my clients is intrested in a web based application, so im trying to play on and learn it a tad. However im comming across lots...
0
by: William Petzke | last post by:
-I implemented the rubberband window from the Microsoft Knowledgebase artice: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q314945 -The rubberband works great however it can be...
1
by: Mas Fabien | last post by:
Hi, I want to manage a rubberband For that, I use the "controlPaint" class. No problem to draw my rectangle, I use "DrawReversibleFrame()" No problem to draw my selection, I use...
1
by: James Proctor | last post by:
Hi there, im brand new to ASP. Ive done loads of VB coding and one of my clients is intrested in a web based application, so im trying to play on and learn it a tad. However im comming across lots...
11
by: Özden Irmak | last post by:
Hello, In my VB.Net application I create a new instance of my form like : NewForm = new MyNewForm() But with this line, this new form is automatically shown. I want it to be hidden at the...
4
by: Tamer via DotNetMonster.com | last post by:
I'm developing a graphic engine. I got all equations made, I need only to understand how I can create a function that, once accepted three values (x; y; z), it returns the two values (X; Y) coming...
11
by: Mark B | last post by:
I want to display a pre-designed graphical 'performance badge' on certain webpages (round, about 2cm diameter) next to a salesperson's details. I have a function,...
4
by: illegal.prime | last post by:
Hi all, I'm getting unexpected results when trying to preload assemblies into an AppDomain I'm creating. Upon creation of the AppDomain - I attach an AssemblyResolve to both my current AppDomain...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.