Usually, you need to know mouse coordinates only when you handle mouse events, but then these coordinates are given to you through the event arguments parameter of your handler. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.mouseeventhandler%28v=vs.110%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.mouseeventargs%28v=vs.110%29.aspx[
^].
System.Windows.Forms.MouseEventArgs.X
and
Y
represent the coordinates in the control's coordinate system.
By the way, you can always do coordinate transform from screen coordinates to the coordinate system of your control and back:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.pointtoclient(v=vs.110).aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.pointtoscreen(v=vs.110).aspx[
^].
This static method gives you mouse position is screen coordinates at any time, regardless of your event handling:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mouseposition(v=vs.110).aspx[
^].
That's all on the topic of mouse coordinates.
But your major problem is different. You should not use
PictureBox
; it won't help you. Even though you could solve the problem with
PictureBox
, it makes no practical sense at all, would only waste your development effort and some extra resources. I'll explain what to do instead. Please see my past answers:
Append a picture within picturebox[
^],
draw a rectangle in C#[
^],
How do I clear a panel from old drawing[
^].
And these are my past answers explaining graphics rendering:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[
^],
capture the drawing on a panel[
^],
Drawing Lines between mdi child forms[
^],
and this one is related specifically to zoom:
Zoom image in C# .net mouse wheel[
^].
Note that zooming means
re-samling of your image, if you use a pixel graphics. Alternatively, you can do it using one of the methods
System.Drawing.Graphics.DrawImage
which accept the parameter specifying the target rectangle, so it will re-sample the image when the new image size is different (take care to preserve the aspect ratio):
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage%28v=vs.110%29.aspx[
^].
Before all such operations, don't forget to set appropriate re-sampling quality using this property:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.interpolationmode%28v=vs.110%29.aspx[
^].
You get the best re-sampling (interpolation) quality when you use
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
. Please see:
http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.interpolationmode%28v=vs.110%29.aspx[
^].
Now, this is a big warning for you: you can easily re-sample the image down, but if you want do increase the size, you can do it only slightly, otherwise your final image quality would be unacceptable.
—SA