Reputation: 5488
I have a PictureBox on a form.
In Load event of the form I create graphics as follows:
imageGraphics = Graphics.FromImage(PictureBox1.Image)
Then, in PictureBox_MouseMove event I draw ellipse:
imageGraphics.FillEllipse(New SolidBrush(brushColor), e.X, e.Y, brushWidth, brushWidth)
No matter what I try, it always draws on incorrect coordinates. I tried e.Location.PointToClient(), PointToScreen(), and Cursor.Position. All far from expected (I need to draw exactly where the cursor is).
Whenever form is resized (and PictureBox, too, as it's Anchor property is set to expand), relative position of drawing to cursor changes.
Is there anything I'm missing?
Upvotes: 0
Views: 489
Reputation: 529
Though this is 1.5 years old, the correct call to get the coordinates relative to PictureBox is:
Dim p1 as point=PictureBox1.PointToClient(Windows.Forms.Cursor.Position)
imageGraphics.FillEllipse(New SolidBrush(brushColor), p1.X, p1.Y, brushWidth, brushWidth)
I guess, it will useful for someone in the future.
Upvotes: 1
Reputation:
This sounds suspiciously like an incorrect sizeMode on your pictureBox. Try making the size of the PictureBox image the same as that of the PictureBox.
Upvotes: 1