473,473 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dragging a line on a panel

Hello, I have to ralize a graph with a pair of straight vertical lines
that have to be dragged in the left-right direction with the mouse.
I've never done something similar so I wonder if someone could tell me
the key C# classes to use.

Thank you very much.

Jul 25 '07 #1
3 2371
On Jul 25, 10:41 am, Beorne <matteo...@gmail.comwrote:
Hello, I have to ralize a graph with a pair of straight vertical lines
that have to be dragged in the left-right direction with the mouse.
I've never done something similar so I wonder if someone could tell me
the key C# classes to use.

Thank you very much.
Check out the System.Drawing; namespace. I guess it will help.... And
also check out this website : http://www.bobpowell.net/beginnersgdi.htm

Jul 25 '07 #2
On Wed, 25 Jul 2007 00:41:07 -0700, Beorne <ma*******@gmail.comwrote:
Hello, I have to ralize a graph with a pair of straight vertical lines
that have to be dragged in the left-right direction with the mouse.
I've never done something similar so I wonder if someone could tell me
the key C# classes to use.
How are you drawing the straight vertical lines now?

There are two basic issues here:

* Drawing the lines
* Handling user input

Drawing the lines is relatively simple, and you may have already
implemented that. In your Control instance's OnPaint method, you use the
PaintEventArgs.Graphics instance to draw whatever you want, including
lines. For example, the Graphics class has a DrawLine() method that can
be used to draw a single line.

Handling the user input is also relatively simple. It involves handling
the mouse events. Again, in your Control instance you can override the
OnMouseDown, OnMouseMove, and OnMouseUp methods so that you can track what
the user does in your control.

In the OnMouseDown method, you do whatever hit-testing you need to figure
out which if any line the mouse was clicked on (compare the mouse
coordinates with the line coordinates...typically you'd actually allow for
the mouse to be some distance away from the line, rather than requiring it
to be exactly on the line). If you hit a line, then you set some sort of
data that indicates which line is being dragged (or if both lines are
always dragged together, you might be able to just set a flag saying that
you're dragging). You'll also need to save the mouse position passed in
the MouseEventArgs for reference later.

In the OnMouseMove method, if you are in the dragging state set in the
OnMouseDown method, you take the current mouse position, subtract it from
the mouse position saved in OnMouseDown, and use that as the offset for
the position of the line or lines being dragged, relative to their
original positions.

Finally, in the OnMouseUp method, you finalize whatever changes were made,
based on the location of the mouse.

As you can see, practically everything is done in your Control-derived
class. There are, of course, other classes you'll need to get data (e.g.
event argument classes) and manage your own data (points, rectangles,
etc.) But there's no other classes per se that are needed. Note that
your Control-derived class could in fact be a Form-derived class.

Pete
Jul 25 '07 #3
On 25 Lug, 21:17, "Peter Duniho" <NpOeStPe...@nnowslpianmk.comwrote:
On Wed, 25 Jul 2007 00:41:07 -0700, Beorne <matteo...@gmail.comwrote:
Hello, I have to ralize a graph with a pair of straight vertical lines
that have to be dragged in the left-right direction with the mouse.
I've never done something similar so I wonder if someone could tell me
the key C# classes to use.

How are you drawing the straight vertical lines now?

There are two basic issues here:

* Drawing the lines
* Handling user input

Drawing the lines is relatively simple, and you may have already
implemented that. In your Control instance's OnPaint method, you use the
PaintEventArgs.Graphics instance to draw whatever you want, including
lines. For example, the Graphics class has a DrawLine() method that can
be used to draw a single line.

Handling the user input is also relatively simple. It involves handling
the mouse events. Again, in your Control instance you can override the
OnMouseDown, OnMouseMove, and OnMouseUp methods so that you can track what
the user does in your control.

In the OnMouseDown method, you do whatever hit-testing you need to figure
out which if any line the mouse was clicked on (compare the mouse
coordinates with the line coordinates...typically you'd actually allow for
the mouse to be some distance away from the line, rather than requiring it
to be exactly on the line). If you hit a line, then you set some sort of
data that indicates which line is being dragged (or if both lines are
always dragged together, you might be able to just set a flag saying that
you're dragging). You'll also need to save the mouse position passed in
the MouseEventArgs for reference later.

In the OnMouseMove method, if you are in the dragging state set in the
OnMouseDown method, you take the current mouse position, subtract it from
the mouse position saved in OnMouseDown, and use that as the offset for
the position of the line or lines being dragged, relative to their
original positions.

Finally, in the OnMouseUp method, you finalize whatever changes were made,
based on the location of the mouse.

As you can see, practically everything is done in your Control-derived
class. There are, of course, other classes you'll need to get data (e.g.
event argument classes) and manage your own data (points, rectangles,
etc.) But there's no other classes per se that are needed. Note that
your Control-derived class could in fact be a Form-derived class.

Pete
Thank you very much!

Jul 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Thomas Reichgruber | last post by:
Hi, does anybody know how to add a linebreak dynamically to a Panel? In the code behind file aspx.cs my webapplication dynamically adds WebControls to a Panel defined in the .aspx file. This...
3
by: Lucas Tam | last post by:
Is there a divider control in VB.NET similar to a Horizontal Line in HTML? In the About Box of VS.NET, there is a divider line at the bottom of the page. -- Lucas Tam (REMOVEnntp@rogers.com)...
2
by: Tull Clancey | last post by:
Does anyone have, or can anyone suggest a URL for code to drag a control around a form at run time? VB.Net 2003. I have written stuff in VB6 to do this before, but a long time ago and I don't...
2
by: Irfan | last post by:
Hi, I have a datagridview and some Buttons on a form. When I drag the form down to increase its size at run time, i want the datagridview also to increase in size so that i can view all the data...
4
by: RobinS | last post by:
I am drawing a rectangle on a picture that has already been drawn on the graphics area (a user control). It works something like this: //in the MouseDown event m_isDragging = true; m_oldX =...
4
by: spectecjr | last post by:
Hey folks; I've got a weird problem... whenever I try to drag and drop a toolbox item onto a form in the Window Forms editor, the control is automatically added on the first click. This gives...
1
by: worldho | last post by:
Hi everyone. I develope GUI that processing images over a map. I used FloatCanvas and wxPython. I successed dragging images and successed to draw a map but failed to drag images over a map......
4
by: lilyumestar | last post by:
I have project I have to do for class. We have to write 4 different .java files. Project2.java HouseGUI.java House.java HouseSorting.java I already finish House.java and I need to work on...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.