Search code examples
c#pictureboxmouseoverresolutionmousemove

I can't get the correct coordinate of an image with mouse over C#


This is my first question ever on Stackoverflow. So I hope it for the best answer.

I want to get correct X and Y coordinate of an Image with mouse over Event (WFA .NET Framework). Take a look at my cursor

The coordinate should be somewhere between 500 for X and 427 for Y, but I only get as I posted. I already maxed out the scroll. And I think the image resolution is correct, here's the image properties

Here's my code:

private void pbInput_MouseMove(object sender, MouseEventArgs e) {        
mouseX.Text = e.X.ToString();
mouseY.Text = e.Y.ToString();
}

And I have a plan to zooming the image for the future, so I put "auto scroll" panel below the picture box.

Could you help me? Thank you so much.

PS: Sorry for my bad English


Solution

  • Try putting picturebox inside panel set panel to:

    this.panel1.AutoScroll = true;
    

    and picturebox to

    this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
    

    this will allow panel to have scroll bars and picturebox will have its full size adjusted to actual picture size