C# 获取DataGridView中DataGridViewRow的坐标?
我需要创建一个函数来获取C# 获取DataGridView中DataGridViewRow的坐标?,c#,winforms,C#,Winforms,我需要创建一个函数来获取Graphics.DrawLine()的数据行的左右坐标 用法: var (x1, y1) = GetCoordinate(row1); // a row from data grid view 1 var (x2, y2) = GetCoordinate(row2); // a row from data grid view 2 graphics.DrawLine(pen, x1, y1, x2, y2); 如何从对象获取坐标DataGridViewRow?您可以使用
Graphics.DrawLine()
的数据行的左右坐标
用法:
var (x1, y1) = GetCoordinate(row1); // a row from data grid view 1
var (x2, y2) = GetCoordinate(row2); // a row from data grid view 2
graphics.DrawLine(pen, x1, y1, x2, y2);
如何从对象获取坐标
DataGridViewRow
?您可以使用以下函数获取(右、上)和(左、下)-这是当前行的边界框
通过使用宽度和高度,您可以轻松地扣除所有四个角的坐标
//X-cordiante of (right,top)
double right = dataGridView1.CurrentRow.AccessibilityObject.Bounds.Right;
//Y-cordiante of (right,top)
double top = dataGridView1.CurrentRow.AccessibilityObject.Bounds.Top;
//X-cordinate of (left,bottom)
double left = dataGridView1.CurrentRow.AccessibilityObject.Bounds.Left;
//Y-cordinate of (left,bottom)
double bottom = dataGridView1.CurrentRow.AccessibilityObject.Bounds.Bottom;
您可以使用以下函数获取(右、上)和(左、下)-这是当前行的边界框 通过使用宽度和高度,您可以轻松地扣除所有四个角的坐标
//X-cordiante of (right,top)
double right = dataGridView1.CurrentRow.AccessibilityObject.Bounds.Right;
//Y-cordiante of (right,top)
double top = dataGridView1.CurrentRow.AccessibilityObject.Bounds.Top;
//X-cordinate of (left,bottom)
double left = dataGridView1.CurrentRow.AccessibilityObject.Bounds.Left;
//Y-cordinate of (left,bottom)
double bottom = dataGridView1.CurrentRow.AccessibilityObject.Bounds.Bottom;
使用适当的事件,
RowBounds
是一个提供的变量。使用适当的事件,RowBounds
是一个提供的变量。