通过


DataGrid.HitTest 方法

定义

获取有关 DataGrid 屏幕上指定点的控件的信息。

重载

名称 说明
HitTest(Int32, Int32)

使用传递给方法的 x 和 y 坐标获取网格中单击点的行号和列号等信息。

HitTest(Point)

获取有关使用特定 Point网格的单击点的行号和列号等信息。

HitTest(Int32, Int32)

Source:
DataGrid.cs
Source:
DataGrid.cs

使用传递给方法的 x 和 y 坐标获取网格中单击点的行号和列号等信息。

public:
 System::Windows::Forms::DataGrid::HitTestInfo ^ HitTest(int x, int y);
public System.Windows.Forms.DataGrid.HitTestInfo HitTest(int x, int y);
member this.HitTest : int * int -> System.Windows.Forms.DataGrid.HitTestInfo
Public Function HitTest (x As Integer, y As Integer) As DataGrid.HitTestInfo

参数

x
Int32

坐标的水平位置。

y
Int32

坐标的垂直位置。

返回

一个 DataGrid.HitTestInfo 包含有关已单击的网格部分的信息。

示例

下面的代码示例在用户单击网格时发生的事件中使用 HitTest 该方法。

Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
    Dim myGrid As DataGrid = CType(sender, DataGrid)
    Dim hti As System.Windows.Forms.DataGrid.HitTestInfo
    hti = myGrid.HitTest(e.X, e.Y)
    Select Case hti.Type
    Case System.Windows.Forms.DataGrid.HitTestType.None 
       Console.WriteLine("You clicked the background.")
    Case System.Windows.Forms.DataGrid.HitTestType.Cell 
       Console.WriteLine("You clicked cell at row " & hti.Row & ", col " & hti.Column)
    Case System.Windows.Forms.DataGrid.HitTestType.ColumnHeader
       Console.WriteLine("You clicked the column header for column " & hti.Column)
    Case System.Windows.Forms.DataGrid.HitTestType.RowHeader 
       Console.WriteLine("You clicked the row header for row " & hti.Row)
    Case System.Windows.Forms.DataGrid.HitTestType.ColumnResize
       Console.WriteLine("You clicked the column resizer for column " & hti.Column)
    Case System.Windows.Forms.DataGrid.HitTestType.RowResize 
       Console.WriteLine("You clicked the row resizer for row " & hti.Row)
    Case System.Windows.Forms.DataGrid.HitTestType.Caption
       Console.WriteLine("You clicked the caption")
    Case System.Windows.Forms.DataGrid.HitTestType.ParentRows 
       Console.WriteLine("You clicked the parent row")
    End Select
 
 End Sub

注解

DataGrid.HitTestInfo控件的方法System.Windows.Forms.DataGrid结合使用HitTest,用于确定用户单击的控件的System.Windows.Forms.DataGrid哪个部分。 包含 DataGrid.HitTestInfo 已单击的网格的行、列和部分。 此外,该 Type 属性返回枚举 DataGrid.HitTestType

该方法HitTest采用控件、DragEnterDragDropDragOverMouseDownMouseUpMouseWheelMouseMove事件提供的 System.Windows.Forms.DataGrid x 和 y 参数。

另请参阅

适用于

HitTest(Point)

Source:
DataGrid.cs
Source:
DataGrid.cs

获取有关使用特定 Point网格的单击点的行号和列号等信息。

public:
 System::Windows::Forms::DataGrid::HitTestInfo ^ HitTest(System::Drawing::Point position);
public System.Windows.Forms.DataGrid.HitTestInfo HitTest(System.Drawing.Point position);
member this.HitTest : System.Drawing.Point -> System.Windows.Forms.DataGrid.HitTestInfo
Public Function HitTest (position As Point) As DataGrid.HitTestInfo

参数

position
Point

表示单个 x,y 坐标的 A Point

返回

一个 DataGrid.HitTestInfo 包含有关网格的特定信息。

示例

以下代码示例在用户单击网格时使用 HitTest 该方法。

Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
    Dim hti As DataGrid.HitTestInfo
    hti = grid.HitTest(New Point(e.X, e.Y))
    Select Case hti.Type
    Case System.Windows.Forms.DataGrid.HitTestType.None 
       Console.WriteLine("You clicked the background.")
    Case System.Windows.Forms.DataGrid.HitTestType.Cell 
       Console.WriteLine("You clicked cell at row " & hti.Row & ", col " & hti.Column)
    Case System.Windows.Forms.DataGrid.HitTestType.ColumnHeader
       Console.WriteLine("You clicked the column header for column " & hti.Column)
    Case System.Windows.Forms.DataGrid.HitTestType.RowHeader 
       Console.WriteLine("You clicked the row header for row " & hti.Row)
    Case System.Windows.Forms.DataGrid.HitTestType.ColumnResize
       Console.WriteLine("You clicked the column resizer for column " & hti.Column)
    Case System.Windows.Forms.DataGrid.HitTestType.RowResize 
       Console.WriteLine("You clicked the row resizer for row " & hti.Row)
    Case System.Windows.Forms.DataGrid.HitTestType.Caption
       Console.WriteLine("You clicked the caption")
    Case System.Windows.Forms.DataGrid.HitTestType.ParentRows 
       Console.WriteLine("You clicked the parent row")
    End Select
 End Sub

注解

DataGrid.HitTestInfo控件的方法System.Windows.Forms.DataGrid结合使用HitTest,用于确定用户单击的控件的System.Windows.Forms.DataGrid哪个部分。 包含 DataGrid.HitTestInfo 已单击的网格的行、列和部分。 此外,该 Type 属性返回枚举 DataGrid.HitTestType

该方法HitTest采用控件、DragEnterDragDropDragOverMouseDownMouseUpMouseWheelMouseMove事件提供的 System.Windows.Forms.DataGrid x 和 y 参数。

另请参阅

适用于