如何在 DataGridView 中获取当前单元格位置 x 和 y? [英] How do I to get the current cell position x and y in a DataGridView?

查看:21
本文介绍了如何在 DataGridView 中获取当前单元格位置 x 和 y?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a Windows form with a calendar which is hidden. I want to show the form right under the current cell of a DataGridView. The position changes according to the position of current cell.

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

I don't want the current cell or current column, I want the position so that I can set the location of my date forms.

这是我正在使用但不起作用的内容:

Here is what I am using but its not working:

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);

推荐答案

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

You can use paygrid.PointToScreen() method.

form_date.Location = paygrid.PointToScreen(
   paygrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location);

这篇关于如何在 DataGridView 中获取当前单元格位置 x 和 y?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆