473,387 Members | 1,365 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,387 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 63241
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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,...

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.