Picturebox coordinates

C

cmac89

Dear Group,

I wonder if anyone can help me with a little VB.NET picturebox problem?

I want to let the user click on a map and where they click I want to
draw a circle. I'm using the PictureBox.MouseDown event to capture the
position of the mouse when the button is clicked. That works fine.
However when I draw a circle at that position the circle is drawn
offset by varying amounts depending on the position of the window. How
can I fix this so that the mouseposition is relative to the picturebox
control?

Craig.
---------------------------------
nx = PictureBox1.MousePosition.X
ny = PictureBox1.MousePosition.Y
Dim message As String
message = CStr(nx) + ", " + CStr(ny)
Label2.Text = (message)
Dim graphics As System.Drawing.Graphics = PictureBox1.CreateGraphics()
Dim rectangle As New
System.Drawing.Rectangle(PictureBox1.MousePosition.X,
PictureBox1.MousePosition.Y, 10, 10)
graphics.DrawEllipse(System.Drawing.Pens.Black, rectangle)
---------------------------------
 
C

cmac89

Hi all again,

After doing my head in for an hour I've just fixed this problem with
PointToClient

Craig
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top