Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取DataGridView中DataGridViewRow的坐标?_C#_Winforms - Fatal编程技术网

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
是一个提供的变量。