簡體   English   中英

獲取已單擊的圖片框的位置

[英]get the position of picturebox that has been clicked

我想獲取鼠標喜歡的圖片框的位置,但是我不知道該怎么做? 我的意思是圖片框的位置,而不是圖片框的形式。 謝謝。

MUGAN的關閉。 您從MouseEventArgs獲得的Point是鼠標的“屏幕”點,其中0,0是整個顯示器或桌面的左上角(無論您想怎么想)。 要將其轉換為PictureBox控件中的“客戶端”點,其中0,0是該PictureBox的左上角,您需要使用Control.PointToClient()方法:

private void pb_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) 
{
    Point mouseDownLocation = (Control)sender.PointToClient(new Point(e.X, e.Y));
    //here goes your if condition ...
}
private void pb_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) 
{
    Point mouseDownLocation = new Point(e.X, e.Y);
    //here goes your if condition ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM