473,728 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
+ 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.imag e.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 63433
You are on the right track using the Picture box MouseMove event, here is a sample:
Put this above your class:
Private LocalMousePosit ion As Point

and this in your Picturebox MouseMove event:

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

TextBox2.Text = ("X=" & LocalMousePosit ion.X & "," & "Y= " & LocalMousePosit ion.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******** ******@TK2MSFTN GP12.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.imag e.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" <jjames700ReMoV eMe at earthlink dot net> wrote in message
news:eZ******** ******@TK2MSFTN GP15.phx.gbl...
You are on the right track using the Picture box MouseMove event, here is a sample: Put this above your class:
Private LocalMousePosit ion As Point

and this in your Picturebox MouseMove event:

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

TextBox2.Text = ("X=" & LocalMousePosit ion.X & "," & "Y= " & LocalMousePosit ion.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******** ******@TK2MSFTN GP12.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.imag e.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.publi c.dotnet.framew ork.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******** *****@tk2msftng p13.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" <jjames700ReMoV eMe at earthlink dot net> wrote in message
news:eZ******** ******@TK2MSFTN GP15.phx.gbl...
You are on the right track using the Picture box MouseMove event, here is

a sample:
Put this above your class:
Private LocalMousePosit ion As Point

and this in your Picturebox MouseMove event:

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

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

LocalMousePosit ion.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******** ******@TK2MSFTN GP12.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.imag e.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
3283
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 components and TransferHandler does not seem to have any means of doing this. The swing DnD API seems to smoother any mouse listeners that I put up, so I don't think that approach will work.
4
13874
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, as opposed to relative to the screen. _______________________________ | * | |_______________________________|
2
21457
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 point on the Panel, and therefore need the mouse coordinates relative to the Panel and not the form itself. Something like: private void myPanel_DragDrop(object sender, DragEventArgs e) {
4
8842
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. Thanks, Henry
0
1361
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 = capCreateCaptureWindowA(lpszName, WS_VISIBLE Or WS_CHILD, 0, 0, DefaultWidth, DefaultHeight, Me.Handle.ToInt32, 0) Now, when I try placing Debug.WriteLine(e.X & "," & e.Y) at the form's
1
2090
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 coord, then click again anywhere on the page to show current Y coord, then go back to normal mouse behavior. must work in firefox 1.5+ Thanks!
4
1653
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 seen several scripts dealing with mouse coordinates, but can't seem to make things work with this. Can anyone help? Thanks...
4
5467
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 spreadsheet programs are capable of properly selecting the cells based on where the mouse is, even though the mouse is way outside the browser. I haven't been able to find any info on it or figure it out myself. How is this possible?
4
3518
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 use only, so I have no fear of this not working in certain browsers, etc. I am no javascript pro but know enough to catch on if anyone is kind enough to help me out here. One of the only ways I could see this working is by having js check the...
0
8753
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9411
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9265
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9188
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9122
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4787
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3230
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
2
2643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2159
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.