2013-02-14 83 views
1

我在我的表单中有panel1,我将可见属性设置为panel1.Visible=false;我想在任何单击屏幕的位置显示此面板。无法将面板位置设置为splitContainer中当前的鼠标位置?

我需要抓住当前鼠标位置,然后显示panel1,其中左上角必须与鼠标光标位于同一点!

对不起,因为如此初学,但我真的坚持如何做到这一点。

代码,我尝试:

private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) 
{ 
    panel1.Location = e.Location; 
    panel1.Show(); 
} 
+0

您发布的代码有什么问题? – Blachshma 2013-02-14 13:09:55

+0

面板出现,但在不同的位置!不是与我的光标@Blachshma – 2013-02-14 13:14:54

回答

1

也许这将是你指导你的任务,只需使用.PointToScreen.GetCellDisplayRectangle方法

private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) 
    { 
     if (e.ColumnIndex == -1) return; 
     var cellRectangle = dataGridView1.PointToScreen(
      dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location); 
     panel1.Location = new Point(cellRectangle.X + 50, cellRectangle.Y - 175); 
     panel1.Show(); 
    } 
+0

Thankyou同一点上的面板的左上角为您的答案。它帮助 – 2013-02-14 15:10:28

+0

不客气':)' – spajce 2013-02-14 15:15:19

0

据我可以识别你的问题,你应该使用PointToScreen功能 - 更多关于这个here

相关问题