views:

31

answers:

1

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?

+1  A: 

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.

Soumya92
If I make PictureBox the same size as the image, it works. But I want to keep scaling of image inside the PB, is that possible?
Sphynx
Eventually I decided to use container with auto scrolling, with PictureBox SizeMode set to AutoSize. That solved the problem.
Sphynx