473,715 Members | 6,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_MouseDow n(object sender,
System.Windows. Forms.MouseEven tArgs e)
{
drag = true;
x = e.X;
y = e.Y;
}

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

{
drag = false;
}

private void label1_MouseMov e(object sender,
System.Windows. Forms.MouseEven tArgs 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 19782

private void label1_MouseMov e(object sender,
System.Windows. Forms.MouseEven tArgs 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*****@hotmai l.com> napisał w wiadomo¶ci
news:bG******** **********@afro dite.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_MouseDow n(object sender,
System.Windows. Forms.MouseEven tArgs e)
{
drag = true;
x = e.X;
y = e.Y;
}

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

{
drag = false;
}

private void label1_MouseMov e(object sender,
System.Windows. Forms.MouseEven tArgs 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
13361
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 mouse until mouse is released and then place the picture there.........can anyone tell me how with a short code example ??
0
2014
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 did was: In an empty form, I set the Form1.Text to "0" and added the following code for Form1.MouseMove event.
7
1608
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) Handles lblP1JoyUp.MouseDown myMouseDown = True mouseX = Cursor.Position.X - Me.Location.X - (lblP1JoyUp.Width / 2)
1
2710
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 familiar with its intricacies, so I'm getting a bunch of errors on certain scenarios. The code below works fine but breaks if I click on Button1 a few times without moving the program window ----------
3
3036
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 MouseHover event. To get a Mousehover I must leave and reenter the control. I'd like to get an event each time the cursor stops moving.
2
3111
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 connecting the two shapes. http://www.blackwaterbadgers.co.uk/image1.bmp Image 1 shows how if you have a line between two shapes, the line is straight. if you have more than one line, the lines will start overlapping
0
1542
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 size. Now the video card displays a section of my screen to the corresponding touch screen. I have a separate app that release the touch(mouse) location on the small touch screen back to my main pc and moves the mouse to the appropriate location on...
3
2721
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 with the mouse. Ide like to be able to do this but with an area on the form. For example, I have a picturebox on the form. When the mouse is down on the picture and they move the mouse, I would like the form to move with it. Any idea how this...
0
2306
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 takes in order to ensure all windows receive the notification that the mouse moved and how windows moves the mouse cursor. What process handles the movement of the mouse cursor and at what point does windows move the mouse cursor vs posting the...
0
8821
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
9340
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
9196
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...
1
9103
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9047
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...
1
6646
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
5967
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4477
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...
3
2118
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.