472,354 Members | 2,231 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

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 62670
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
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
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
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
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
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
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
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
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
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

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.