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

mouseposition.x or mouseposition.y not really the position

hi, im trying to egt a picturebox to follow the mousecursor around in a
certain area, but the picturebox isnt where the mouse is...how can i get the
picturebox to be where the mouse cursor is? thanks
--
-iwdu15
Nov 21 '05 #1
7 7590
Post Code

"iwdu15" <iw****@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
hi, im trying to egt a picturebox to follow the mousecursor around in a
certain area, but the picturebox isnt where the mouse is...how can i get
the
picturebox to be where the mouse cursor is? thanks
--
-iwdu15

Nov 21 '05 #2
Hi,

Here is some sample code on how to move a label and button. I
hope it helps. The label I add to the form with code and button I dropped
on the form in the designer.

Dim bMoving As Boolean = False
Dim WithEvents lbl As Label
Dim bMovelbl As Boolean = False
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
lbl = New Label
With lbl
.Location = New Point(10, 10)
.Text = "Move Me"
.BackColor = Color.Transparent
End With

Me.Controls.Add(lbl)

End Sub

Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
bMoving = True
End Sub
Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
Static oldX, oldY As Integer

If bMoving Then
Button1.Location = New Point(Button1.Left + e.X - oldX,
Button1.Top + e.Y - oldY)
Else
oldX = e.X
oldY = e.Y
End If
End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
bMoving = False
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
MessageBox.Show(Button1.Location.ToString)
End Sub

Private Sub lbl_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lbl.MouseDown
bMovelbl = True
End Sub

Private Sub lbl_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lbl.MouseUp
bMovelbl = False
End Sub

Private Sub lbl_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lbl.MouseMove
Static oldX, oldY As Integer

If bMovelbl Then
lbl.Location = New Point(lbl.Left + e.X - oldX, lbl.Top + e.Y -
oldY)
Else
oldX = e.X
oldY = e.Y
End If

End Sub
Ken
-------------------------
"iwdu15" <iw****@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
hi, im trying to egt a picturebox to follow the mousecursor around in a
certain area, but the picturebox isnt where the mouse is...how can i get
the
picturebox to be where the mouse cursor is? thanks
--
-iwdu15

Nov 21 '05 #3
Iwdu,

When I saw Ken's sample I had to think about this.

http://www.vb-tips.com/default.aspx?...1-47ef665ea0c2

:-))

Cor
Nov 21 '05 #4
"iwdu15" <iw****@discussions.microsoft.com> schrieb:
hi, im trying to egt a picturebox to follow the mousecursor around in a
certain area, but the picturebox isnt where the mouse is...how can i get
the
picturebox to be where the mouse cursor is? thanks


How do you determine the position of the mouse? Are you using 'e.X'/'e.Y'
in a control's 'MouseMove' event handler? When doing so, you'll have to
place the control you want to move in this container, or you'll have to
convert the coordinates using 'Control.PointTo*'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
i was just using this for example

me.button1.top = me.mouseposition.y
me.button1.left = me.mouseposition.x

but that didnt work, i found a different way of moving it but il try
implimenting the mouse move thing i wanted to ealier, now that you guys told
me how to achieve this....thank you
Nov 21 '05 #6
I have found that if you use PointToClient you get a more accurate position for the mouse, like so:

LocalMousePosition = PictureBox1.PointToClient(Cursor.Position)

TextBox2.Text = ("X=" & LocalMousePosition.X & "," & "Y= " & LocalMousePosition.Y)
james

"iwdu15" <iw****@discussions.microsoft.com> wrote in message news:F9**********************************@microsof t.com...
i was just using this for example

me.button1.top = me.mouseposition.y
me.button1.left = me.mouseposition.x

but that didnt work, i found a different way of moving it but il try
implimenting the mouse move thing i wanted to ealier, now that you guys told
me how to achieve this....thank you

Nov 21 '05 #7

"james" <jjames700ReMoVeMe at earthlink dot net> wrote in message news:Ou****************@TK2MSFTNGP09.phx.gbl...
I have found that if you use PointToClient you get a more accurate position for the mouse, like so:

LocalMousePosition = PictureBox1.PointToClient(Cursor.Position)

TextBox2.Text = ("X=" & LocalMousePosition.X & "," & "Y= " & LocalMousePosition.Y)
james


Sorry, after re-reading your original post, I see that you are trying to get the Picturebox to follow the mousepointer, not get
accurate mouse coordinates within the picturebox. Instead of PointToClient, I would suggest you use PointToScreen to get
accurate info for the mouse pointer on your form.
james

Nov 21 '05 #8

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

Similar topics

3
by: Dade Murphy | last post by:
Hi everyone! I've got a little problem and just cann't find any solution for it: I need to get the current position of the mousecursor at my webpage for some overlay stuff. Currently I use the...
1
by: bloy.d | last post by:
Hi, I'll be honest I'm a newbie at all this and I'm need to get a small JS working as soon as possible - please can anybody help? I have a small insentive if needed ;) What i need is a spot...
1
by: Scatropolis | last post by:
How do I set the MousePosition? I found MousePosition but it says it can't modified it because it isn't a variable. thanks
8
by: nescio | last post by:
hello, i have a script that finds the x and y from the mouse position, this works fine. but now i have an image in a layer : <div id='someLayer'> <img src='someImage.jpg'> </div>
1
by: laurakr | last post by:
I am trying to use a clear to get my bottom nav bar below the quote box on the right, but it isn't working. I would like the bottom edge of the quote box to "stick" to the footer nav bar but copy...
1
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
When using Control.MousePosition the x values seems to be just fine when I draw something on the screen, but the Y value seems to have got an offset - independently of where on the screen I put the...
0
by: raylopez99 | last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to modify a Point, which I had made have a property. It's pointless to do this (initially it will compile, but you'll run into...
10
by: doubleac | last post by:
Hi This is the first time for me asking for help in forums on the net. I hope ill make myself understood. And sorry for my bad english. I have 4 classes: Spelare, Händelser, SpelPlan and Start....
2
by: ducttape | last post by:
Hello I'm busy working with an MDI parent and child forms. I've found that there is a discrepancy between the locations returned by DesktopLocation, Control.MousePosition and MouseEventArgs...
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: 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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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...

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.