473,386 Members | 1,790 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,386 software developers and data experts.

Moving a control by mouse

Hello,

I want to move a control by mouse on a form. I use the following code to
mouse a label for example:

private void label1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
drag = true;
x = e.X;
y = e.Y;
}

private void label1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)

{
drag = false;
}

private void label1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)

{
if(drag)
{
label1.Left += e.X-x;
label1.Top += e.Y-y;
x = e.X;
y = e.Y;
}
}

The label acts verry strange, jumping around everywhere...

What I'm I doing wrong?

Thx in advance
Nov 15 '05 #1
1 19663

private void label1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)

{
if(drag)
{
label1.Left += e.X-x; repleace with label1.Left=e.X
label1.Top += e.Y-y; label1.Top=e.Y
x = e.X;
y = e.Y;
}
} I dont chek this solution try it.
Użytkownik "Fredje" <co*****@hotmail.com> napisał w wiadomo¶ci
news:bG******************@afrodite.telenet-ops.be... Hello,

I want to move a control by mouse on a form. I use the following code to
mouse a label for example:

private void label1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
drag = true;
x = e.X;
y = e.Y;
}

private void label1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)

{
drag = false;
}

private void label1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)

{
if(drag)
{
label1.Left += e.X-x;
label1.Top += e.Y-y;
x = e.X;
y = e.Y;
}
}

The label acts verry strange, jumping around everywhere...

What I'm I doing wrong?

Thx in advance

Nov 15 '05 #2

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

Similar topics

3
by: Steen Gellett | last post by:
Hey...........is it possible to move a picture around the form with the mouse ? I have a form with one picture on it........when I hold down the mouse I would like the picture to follow the...
0
by: Sam Sungshik Kong | last post by:
Hello! If I understand correctly, MouseMove event is triggered when the mouse moves (ie when point changes). I, however, found out that it's triggered even if the mouse is not moving. What I...
7
by: jcrouse | last post by:
I use the following three subs to click on a label and reposition it at runtime: Private Sub lblP1JoyUp_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)...
1
by: siliconpi | last post by:
I'm looking for the simplest and cleanest way of having 10 buttons on a form, on which if I move my mouse over, a label's text changes as specified. I'm using Visual Basic .NET and I'm not too...
3
by: Just Me | last post by:
If I move the mouse cursor over a control and stop moving I get a MouseHover event. If I then move the cursor while staying within the control and then stop moving I do not get another...
2
by: Carl Gilbert | last post by:
Hi I have a math kinda problem where I'm trying to split some lines when two or more lines connect two shapes. The reason I am doing this is to make it clear that there are multiple lines...
0
by: =?Utf-8?B?QW5kcmV3?= | last post by:
I have 6 small touch screens that are connected to my pc to a special video card. The video driver splits up my screen in six sections, 3 across the top and 3 across the bottom. They are all even...
3
VBWheaties
by: VBWheaties | last post by:
In vb.net, I want to allow a user to click and drag a form like what is supported when you click and drag a moveable forms title bar: you click and hold titlebar, then move the mouse, the form moves...
0
by: Studlyami | last post by:
I am trying to find how windows translate the input from a HID device to an actual windows message; specifically, the mouse. I am trying to figure out how when the mouse moves the process windows...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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...
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
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,...
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...

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.