鼠标位置(Cursor.Position)

时间:2015-02-15 20:03:17

标签: c# image mouseevent picturebox pixels

我有图像10 * 10多它因素并将图像加载到图片框我有问题选择鼠标位置当我点击图像上的点到处左上角的左上角是什么错误?

1 个答案:

答案 0 :(得分:0)

要绘制Image缩放 PictureBox,这对我来说很好用:

float zoom = 7.5f;

public Form1()
{
    InitializeComponent();
    pb1.SizeMode = PictureBoxSizeMode.Zoom;
    pb1.ClientSize = new Size((int) (pb1.Image.Size.Width  * zoom), 
                              (int) (pb1.Image.Size.Height * zoom) );
}



private void pb1_MouseClick(object sender, MouseEventArgs e)
{
   int x = (int)Math.Round(e.X / zoom) ;
   int y = (int)Math.Round(e.Y / zoom) ;
   Bitmap bmp = (Bitmap) pb1.Image;
   bmp.SetPixel(x, y, Color.Red);
   pb1.Refresh();
}

注意:如果PictureBox位于AutoScroll Panel,这同样有效。

enter image description here enter image description here