DataGridView.HitTestInfo DataGridView.HitTestInfo DataGridView.HitTestInfo DataGridView.HitTestInfo Class

定义

包含关于 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.HitTestInfoDataGridView.HitTestInfoDataGridView.HitTestInfoDataGridView.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

注解

HitTest方法DataGridView类返回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 Nowhere Nowhere Nowhere

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

属性

ColumnIndex ColumnIndex ColumnIndex ColumnIndex

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

ColumnX ColumnX ColumnX 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 RowIndex RowIndex RowIndex

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

RowY RowY RowY 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 Type Type 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) Equals(Object) Equals(Object) Equals(Object)

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

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

GetType() GetType() GetType() GetType()

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

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
ToString() ToString() ToString() ToString()

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

适用于

另请参阅