如何在DataGridView中获取当前单元格位置x和y?

use*_*584 14 .net c# datagridview

我有一个带有隐藏日历的Windows表单.我想在DataGridView的当前单元格下面显示表单.位置根据当前单元格的位置而变化.

我不想要当前的单元格或当前列,我想要的位置,以便我可以设置我的日期表单的位置.

这是我正在使用但它不工作:

int po_X = paygrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Left+paygrid.Left;
int po_Y = paygrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Bottom+paygrid.Top;
form_date.Location = new System.Drawing.Point(po_X, po_Y);
Run Code Online (Sandbox Code Playgroud)

wat*_*rif 20

您可以使用paygrid.PointToScreen()方法.

form_date.Location = paygrid.PointToScreen(
   paygrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location);
Run Code Online (Sandbox Code Playgroud)