DataGridView.HitTestInfo 类

定义

包含关于 DataGridView 控件中指定坐标对的信息,如行和列索引。Contains information, such as the row and column indexes, about a specific coordinate pair in the DataGridView control. 此类不能被继承。This class cannot be inherited.

public: ref class DataGridView::HitTestInfo sealed
public sealed class DataGridView.HitTestInfo
type DataGridView.HitTestInfo = class
Public NotInheritable Class DataGridView.HitTestInfo
继承
DataGridView.HitTestInfo

示例

下面的代码示例演示如何使用此类型。The following code example illustrates the use of this type. 此示例是DataGridView.Columns属性参考主题中提供的一个更大示例的一部分。This example is part of a larger example available in the DataGridView.Columns property reference topic.

private DataGridViewCell clickedCell;

private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
// If the user right-clicks a cell, store it for use by the shortcut menu.
    if (e.Button == MouseButtons.Right)
    {
        DataGridView.HitTestInfo hit = dataGridView1.HitTest(e.X, e.Y);
        if (hit.Type == DataGridViewHitTestType.Cell)
        {
            clickedCell =
                dataGridView1.Rows[hit.RowIndex].Cells[hit.ColumnIndex];
        }
    }
}
Private clickedCell As DataGridViewCell

Private Sub dataGridView1_MouseDown(ByVal sender As Object, _
    ByVal e As MouseEventArgs) Handles dataGridView1.MouseDown

    ' If the user right-clicks a cell, store it for use by the 
    ' shortcut menu.
    If e.Button = MouseButtons.Right Then
        Dim hit As DataGridView.HitTestInfo = _
            dataGridView1.HitTest(e.X, e.Y)
        If hit.Type = DataGridViewHitTestType.Cell Then
            clickedCell = _
                dataGridView1.Rows(hit.RowIndex).Cells(hit.ColumnIndex)
        End If
    End If

End Sub

注解

DataGridView类的HitTest方法返回DataGridView.HitTestInfoThe HitTest method of the DataGridView class returns a DataGridView.HitTestInfo. 您可以使用此方法来确定DataGridView控件的哪个部分位于指定的坐标处。You can use this method to determine which part of the DataGridView control is located at the specified coordinates. 例如, 可以通过指定鼠标单击的坐标来调用此方法, 以确定单击的单元格的行索引和列索引, 或者是否单击了标题单元或滚动条。For example, you can call this method specifying the coordinates of a mouse click to determine the row and column indexes of the clicked cell or whether a header cell or scroll bar was clicked.

字段

Nowhere

指定该点不在单元格或单元格标头。Specifies that the point is not on a cell or cell header. 此字段为只读。This field is read-only.

属性

ColumnIndex

获取包含当前 DataGridView.HitTestInfo 所描述的坐标的列的索引。Gets the index of the column that contains the coordinates described by the current DataGridView.HitTestInfo.

ColumnX

获取列开头的 x 坐标,该列包含当前 DataGridView.HitTestInfo 所描述的坐标。Gets the x-coordinate of the beginning of the column that contains the coordinates described by the current DataGridView.HitTestInfo.

RowIndex

获取包含当前 DataGridView.HitTestInfo 所描述的坐标的行的索引。Gets the index of the row that contains the coordinates described by the current DataGridView.HitTestInfo.

RowY

获取行顶部的 y 坐标,该行包含当前 DataGridView.HitTestInfo 所描述的坐标。Gets the y-coordinate of the top of the row that contains the coordinates described by the current DataGridView.HitTestInfo.

Type

获取 DataGridViewHitTestType,它指示当前 DataGridView 所描述的坐标属于 DataGridView.HitTestInfo 的哪个部分。Gets the DataGridViewHitTestType that indicates which part of the DataGridView the coordinates described by the current DataGridView.HitTestInfo belong to.

方法

Equals(Object)

确定指定的 Object 是否等同于当前的 DataGridView.HitTestInfoDetermines whether the specified Object is equal to the current DataGridView.HitTestInfo.

GetHashCode()

用作特定类型的哈希函数。Serves as a hash function for a particular type.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示 DataGridView.HitTestInfo 的字符串。Returns a string that represents a DataGridView.HitTestInfo.

适用于

另请参阅