datagridview的替代方法 - getcelldisplayrectangle方法 [英] Alternative to datagridview - getcelldisplayrectangle method

查看:1106
本文介绍了datagridview的替代方法 - getcelldisplayrectangle方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要得到两个单元矩形边界的x和y坐标。目前,我在

I need to get the x and y coordinates of two cells rectangle boundary. At the moment, I am using

GetCellDisplayRectangle

事件中使用

dataGridView1_Paint(object sender, PaintEventArgs e)

方法。



问题是如果在屏幕上看不到单元格,我的x和y值为0.



即使单元格在屏幕上不可见,获取两个单元格的x和y坐标的替代方法是什么?



我尝试过:



event.

The problem is that I get 0 for x and y value if the cells is not visible on the screen.

What would be the alternative method to get x and y coordinates of two cells even if the cells are not visible on screen ?

What I have tried:

Rectangle cell_1 = dataGridView1.GetCellDisplayRectangle(column1, row1, false);
Rectangle cell_2 = dataGridView1.GetCellDisplayRectangle(column2, row2, false);

int x1 = cell_1.Right;
int y1 = (cell_1.Top + cell_1.Bottom) / 2;

int x2 = cell_2.Right;
int y2 = (cell_2.Top + cell_2.Bottom) / 2;

推荐答案

如果网格在屏幕上不可见,那么任何东西都不会有x,y值。只有在屏幕上绘制控件时才会设置位置和尺寸。
If the grid is not visible on the screen then nothing will have x,y values. The position and dimensions only get set when the control is painted on the screen.


这篇关于datagridview的替代方法 - getcelldisplayrectangle方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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