473,657 Members | 2,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Re versible 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 11257
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**********@h otmail.com> wrote in
news:uP******** ******@TK2MSFTN GP12.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.Re versible 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**********@h otmail.com> schreef in bericht
news:uP******** ******@TK2MSFTN GP12.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.Re versible 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
3520
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) template. Briefly -------------------------------------------------------------------------------------------- I need to create dynamically some controls on the forms, and display these
3
2655
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 of problems. Up until now ive managed to sort most of them, but now im strugling. When i run my application i keep getting this. Server Error in '/WebApplication1' Application....
0
1037
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 stretched outside of the form boundary. I need to find a way to contain it within the ClientRectangle of a Windows form. -I have already tried checking if the current X, Y location in the
1
4505
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 "DrawSelectionFrame()" No problem to draw my hands, I use "DrawGrabHandle()" But after, I don't know how to do to erase my selection and my hands. And how can I manage my hands ? Fabien :)
1
3402
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 of problems. Up until now ive managed to sort most of them, but now im strugling. When i run my application i keep getting this. Server Error in '/WebApplication1' Application...
11
2190
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 start... Adding a line after this line like :
4
4225
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 from two distinct mathematical processes. I don't want to use another global variable, I'm trying to be fast, in order to use such a function even in this way: Public Structure Point x as double y as double z as double
11
5367
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, fGetPerformanceGrade(SalesPersonID as Long) as String to retrieve that salesperson's grade (e.g. A+, A, A-, B+, B... D). Also one other function, fGetMonthlySales(SalesPersonID as Long) as String to get their sales figure, e.g. "$87K". I want web visitors to be able to click...
4
5337
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 and the new AppDomain I create. I copy all the assemblies/dlls into a new directory and then try loading them all into the new AppDomain using the following: private void LoadAssembliesFromDirectory(AppDomain appDomain, string directory)
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.