473,491 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Get Mouse coordinates of Image in PictureBox

Tom
I have a picturebox on my VB.NET form. The picturebox size mode is set to
stretched. I then load an image into that form and display it. As the user
moves the mouse over the form, I want to get and display (in the status bar)
the image coordinates of the mouse location. However, if I use the
picturebox's MouseMove event, I am getting the coordinates of the mouse over
the PICTUREBOX, not the actual image underneath that (which is stretched).
i.e. if the actual image has a width of 2000, and I move the cursor over to
the right side of the stretched picturebox image, I am only getting a left
pixel value of around 1000 - because it is getting the mouse x:y coordinates
of the picture box, not the actual image.

How can I accomplish this? There isn't any picturebox.image.mousemove event
that I can see. How can I translate what the picturebox gives me back to the
coordinates of the actual image underneath it? Or have I got to go about
this differently?

Thanks.

Tom
Nov 21 '05 #1
3 63288
You are on the right track using the Picture box MouseMove event, here is a sample:
Put this above your class:
Private LocalMousePosition As Point

and this in your Picturebox MouseMove event:

LocalMousePosition = PictureBox1.PointToClient(Cursor.Position)

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

This will give you the correct position within your Image. I have a better example of this at this link:

http://www.gotdotnet.com/Community/U...0-e3d1ca40c74a

james
aka: Trucker


"Tom" <to*@nospam.com> wrote in message news:u0**************@TK2MSFTNGP12.phx.gbl...
I have a picturebox on my VB.NET form. The picturebox size mode is set to
stretched. I then load an image into that form and display it. As the user
moves the mouse over the form, I want to get and display (in the status bar)
the image coordinates of the mouse location. However, if I use the
picturebox's MouseMove event, I am getting the coordinates of the mouse over
the PICTUREBOX, not the actual image underneath that (which is stretched).
i.e. if the actual image has a width of 2000, and I move the cursor over to
the right side of the stretched picturebox image, I am only getting a left
pixel value of around 1000 - because it is getting the mouse x:y coordinates
of the picture box, not the actual image.

How can I accomplish this? There isn't any picturebox.image.mousemove event
that I can see. How can I translate what the picturebox gives me back to the
coordinates of the actual image underneath it? Or have I got to go about
this differently?

Thanks.

Tom

Nov 21 '05 #2
Tom
James: Hmm, it doesn't seem to be working. Using the code you gave me gives
me the same results as if I used:

TextBox2.Text = ("X=" & e.X & "," & "Y= " & e.Y)

in the PictureBox MouseMove event.

Remember, the image in the picture box is stretched to fill the picture box;
the actual image underneath is much bigger. So, say, pointing the mouse at
location 500x500 in the picturebox (i.e. the e.X and e.Y position) image
might actually be the pixal at 900x900 in the actual underlying image.

I'll take a look at your code in your referenced URL, but got any more
ideas?

Tom

"james" <jjames700ReMoVeMe at earthlink dot net> wrote in message
news:eZ**************@TK2MSFTNGP15.phx.gbl...
You are on the right track using the Picture box MouseMove event, here is a sample: Put this above your class:
Private LocalMousePosition As Point

and this in your Picturebox MouseMove event:

LocalMousePosition = PictureBox1.PointToClient(Cursor.Position)

TextBox2.Text = ("X=" & LocalMousePosition.X & "," & "Y= " & LocalMousePosition.Y)
This will give you the correct position within your Image. I have a better example of this at this link:
http://www.gotdotnet.com/Community/U...0-e3d1ca40c74a
james
aka: Trucker


"Tom" <to*@nospam.com> wrote in message

news:u0**************@TK2MSFTNGP12.phx.gbl...
I have a picturebox on my VB.NET form. The picturebox size mode is set to
stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and display (in the status bar) the image coordinates of the mouse location. However, if I use the
picturebox's MouseMove event, I am getting the coordinates of the mouse over the PICTUREBOX, not the actual image underneath that (which is stretched). i.e. if the actual image has a width of 2000, and I move the cursor over to the right side of the stretched picturebox image, I am only getting a left pixel value of around 1000 - because it is getting the mouse x:y coordinates of the picture box, not the actual image.

How can I accomplish this? There isn't any picturebox.image.mousemove event that I can see. How can I translate what the picturebox gives me back to the coordinates of the actual image underneath it? Or have I got to go about
this differently?

Thanks.

Tom


Nov 21 '05 #3
Ack!! I forgot that the code I gave you (and the sample I linked to) both depend on a Picturebox set to AutoSize and the
Picturebox being on top of a Panel Control.........<blush>(to allow scrolling of the image)
I believe that you can still accomplish what you want ,but, it will require a few more things to get it working.
In the sample I linked to, you can resize the image up and down , and still get the proper X & Y coordinates. And that is also
what the code snippet I gave depends on.
I think you will need to not use the PictureBox for your image.
You might want to checkout Bob Powell's GDI+ FAQ at this link: http://www.bobpowell.net/gdiplus_faq.htm

Also, you might post your question in this newsgroup:
microsoft.public.dotnet.framework.drawing
There are a lot of people there very familiar with what you are trying to do.
Good luck.
james

"Tom" <to*@nospam.com> wrote in message news:eS*************@tk2msftngp13.phx.gbl...
James: Hmm, it doesn't seem to be working. Using the code you gave me gives
me the same results as if I used:

TextBox2.Text = ("X=" & e.X & "," & "Y= " & e.Y)

in the PictureBox MouseMove event.

Remember, the image in the picture box is stretched to fill the picture box;
the actual image underneath is much bigger. So, say, pointing the mouse at
location 500x500 in the picturebox (i.e. the e.X and e.Y position) image
might actually be the pixal at 900x900 in the actual underlying image.

I'll take a look at your code in your referenced URL, but got any more
ideas?

Tom

"james" <jjames700ReMoVeMe at earthlink dot net> wrote in message
news:eZ**************@TK2MSFTNGP15.phx.gbl...
You are on the right track using the Picture box MouseMove event, here is

a sample:
Put this above your class:
Private LocalMousePosition As Point

and this in your Picturebox MouseMove event:

LocalMousePosition = PictureBox1.PointToClient(Cursor.Position)

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

LocalMousePosition.Y)

This will give you the correct position within your Image. I have a

better example of this at this link:

http://www.gotdotnet.com/Community/U...0-e3d1ca40c74a

james
aka: Trucker


"Tom" <to*@nospam.com> wrote in message

news:u0**************@TK2MSFTNGP12.phx.gbl...
>I have a picturebox on my VB.NET form. The picturebox size mode is set to
> stretched. I then load an image into that form and display it. As the user > moves the mouse over the form, I want to get and display (in the status bar) > the image coordinates of the mouse location. However, if I use the
> picturebox's MouseMove event, I am getting the coordinates of the mouse over > the PICTUREBOX, not the actual image underneath that (which is stretched). > i.e. if the actual image has a width of 2000, and I move the cursor over to > the right side of the stretched picturebox image, I am only getting a left > pixel value of around 1000 - because it is getting the mouse x:y coordinates > of the picture box, not the actual image.
>
> How can I accomplish this? There isn't any picturebox.image.mousemove event > that I can see. How can I translate what the picturebox gives me back to the > coordinates of the actual image underneath it? Or have I got to go about
> this differently?
>
> Thanks.
>
> Tom
>
>



Nov 21 '05 #4

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

Similar topics

1
3255
by: cte | last post by:
I have a swing program involving drag and drop - implemented with javax.swing.TransferHandler etc. My problem is that I want to determine the mouse coordinates of a drop onto one of my...
4
13853
by: Jonne | last post by:
Hi, I haven't found anything like this anywhere with Google, so I'm posting it here, hoping one of you people knows how to do something like this. I'm trying to get the mouse coordinates in a div,...
2
21393
by: Robin Senior | last post by:
Hi, I'm trying to drag and drop onto a Panel on my form. The panel is inside a groupBox, which of course is inside my form. When dropping the item onto my Panel, I want it to appear at that...
4
8813
by: Henry Wu | last post by:
Hi, I see examples of Magnifying an area under mouse coordinates to a form or picturebox using VB6 and VC6, does anyone know how to do it under VB.NET? Its nice to use the new GDI+ for it. ...
0
1347
by: Henry C. Wu | last post by:
Hi, I have a form that has a video "inserted" at the form's Handle. Like so: '//Create Capture Window capGetDriverDescriptionA(0, lpszName, 100, lpszVer, 100) '// Retrieves driver info lwndC =...
1
2067
by: finerrecliner | last post by:
trying to get the mouse coordinates to show up in an alert box. but all i get is "undefined" the script should work like: click the button, then click anywhere on the page to show your current x...
4
1618
by: Luongo | last post by:
Hi, I'm working on a project in which I'd like to have the user's mouse click coordinates included in a php URL which would load onClick, for example http://...imagecreate.php?x=200&y=100. I've...
4
5431
by: atn2002 | last post by:
How can I track the mouse coordinates outside the active window? No one can tell me its not possible because Google Spreadsheets and EditGrid both do it. When you drag down to select cells these...
4
3482
by: mbatestblrock | last post by:
I hope this makes some sense. My ultimate goal here is to execute a block of code if the mouse has not moved in a minute or so within the broswer. The machine I am running this on is for internal...
0
7115
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
6978
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
7190
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
7360
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...
1
4881
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
4578
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
3086
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...
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
280
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...

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.