winform里,在datagridview里点击某一个单元格弹出一个模式窗口,我要实现的是:datagridview所在的窗口的大小尺寸即使有变化,弹出的模式窗口左上角的位置总能对齐显示在刚才点击的datagridview单元格的左下角。先谢谢了。

解决方案 »

  1.   

    获取你要弹出的那个模式窗口的句柄,然后使用API函数SetWindowPos,设置该窗口的弹出位置即可。需要注意屏幕坐标与控件坐标的关系。
      

  2.   

    添加DataGridView.CellClick事件,在事件里实现:        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
            {
                DataGridView dgv = (DataGridView)sender;
                System.Drawing.Rectangle rec = dgv.RectangleToScreen(dgv.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false));            Form2 frm = new Form2();
                frm.StartPosition = FormStartPosition.Manual;
                frm.Location = new System.Drawing.Point(rec.Left, rec.Bottom);
                frm.ShowDialog();
            }Form2是你的模式窗口类。