473,586 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7610
Post Code

"iwdu15" <iw****@discuss ions.microsoft. com> wrote in message
news:84******** *************** ***********@mic rosoft.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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
lbl = New Label
With lbl
.Location = New Point(10, 10)
.Text = "Move Me"
.BackColor = Color.Transpare nt
End With

Me.Controls.Add (lbl)

End Sub

Private Sub Button1_MouseDo wn(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles Button1.MouseDo wn
bMoving = True
End Sub
Private Sub Button1_MouseMo ve(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles Button1.MouseMo ve
Static oldX, oldY As Integer

If bMoving Then
Button1.Locatio n = New Point(Button1.L eft + 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.MouseEven tArgs) Handles Button1.MouseUp
bMoving = False
End Sub

Private Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click
MessageBox.Show (Button1.Locati on.ToString)
End Sub

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

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

Private Sub lbl_MouseMove(B yVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) 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****@discuss ions.microsoft. com> wrote in message
news:84******** *************** ***********@mic rosoft.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****@discuss ions.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.PointT o*'.

--
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.mousepositio n.y
me.button1.left = me.mousepositio n.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:

LocalMousePosit ion = PictureBox1.Poi ntToClient(Curs or.Position)

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

"iwdu15" <iw****@discuss ions.microsoft. com> wrote in message news:F9******** *************** ***********@mic rosoft.com...
i was just using this for example

me.button1.top = me.mousepositio n.y
me.button1.left = me.mousepositio n.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" <jjames700ReMoV eMe at earthlink dot net> wrote in message news:Ou******** ********@TK2MSF TNGP09.phx.gbl. ..
I have found that if you use PointToClient you get a more accurate position for the mouse, like so:

LocalMousePosit ion = PictureBox1.Poi ntToClient(Curs or.Position)

TextBox2.Text = ("X=" & LocalMousePosit ion.X & "," & "Y= " & LocalMousePosit ion.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
1561
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 following code for this: if (ieDom) { // Internet Explorer X=window.event.clientX + document.body.scrollLeft;
1
3553
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 the ball page. An image on a HTML page that on mouse press stores to position of the crosshair into a X and Y box and works for most browers if not all...
1
3149
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
1738
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
2036
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 to be able to flow to the left of the quote box. For the bonus round I would like the right edge of the box to align with the right edge of the...
1
3689
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 cursor the item I draw is a fixed offset below the cursor - why is this so?
0
2182
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 problems later). Apparently Point is a struct, a value type, and it does not behave like a classic structure (in my mind's eye, and see below)....
10
1636
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. In the class "Händelser" a random message apperas, if the players land on a couple of specific squares. A message is supposed to change the...
2
5444
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 e.Location, but I can't work out why or what exactly the discrepancy is. My forms are all custom without title bars and thus I've had to create my own...
0
7912
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...
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
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. ...
1
7959
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...
0
5390
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...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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 we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
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...

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.