DataGrid.HitTest DataGrid.HitTest DataGrid.HitTest DataGrid.HitTest Method

定义

获取屏幕上指定点的 DataGrid 控件的信息。Gets information about the DataGrid control at a specified point on the screen.

重载

HitTest(Int32, Int32) HitTest(Int32, Int32) HitTest(Int32, Int32) HitTest(Int32, Int32)

使用传递给方法的 x 和 y 坐标获取信息(如网格上被单击点的行号和列号)。Gets information, such as row and column number of a clicked point on the grid, using the x and y coordinate passed to the method.

HitTest(Point) HitTest(Point) HitTest(Point) HitTest(Point)

获取有关使用特定 Point 的网格的信息(如网格中被单击点的行号和列号)。Gets information, such as row and column number of a clicked point on the grid, about the grid using a specific Point.

HitTest(Int32, Int32) HitTest(Int32, Int32) HitTest(Int32, Int32) HitTest(Int32, Int32)

使用传递给方法的 x 和 y 坐标获取信息(如网格上被单击点的行号和列号)。Gets information, such as row and column number of a clicked point on the grid, using the x and y coordinate passed to the method.

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 Int32 Int32 Int32

坐标的水平位置。The horizontal position of the coordinate.

y
Int32 Int32 Int32 Int32

坐标的垂直位置。The vertical position of the coordinate.

返回

一个 DataGrid.HitTestInfo,它包含有关网格中被单击部分的信息。A DataGrid.HitTestInfo that contains information about the clicked part of the grid.

示例

下面的代码示例在用户HitTest单击网格时发生的事件中使用方法。The following code example uses the HitTest method in an event that occurs when the user clicks in the grid.

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
 

注解

与控件的HitTest方法System.Windows.Forms.DataGrid一起使用, 以确定用户已单击控件的哪个部分。 DataGrid.HitTestInfo System.Windows.Forms.DataGridThe DataGrid.HitTestInfo, in conjunction with the HitTest method of the System.Windows.Forms.DataGrid control, is used to determine which part of a System.Windows.Forms.DataGrid control the user has clicked. DataGrid.HitTestInfo包含所单击的网格的行、列和部分。The DataGrid.HitTestInfo contains the row, column, and part of the grid that was clicked. 此外, Type属性DataGrid.HitTestType返回枚举。Additionally, the Type property returns a DataGrid.HitTestType enumeration.

DragDrop方法采用DragEnterMouseDown控件的、、 、、和MouseWheel事件提供的 x 和 y 参数。 MouseUp DragOver System.Windows.Forms.DataGrid HitTest MouseMoveThe HitTest method takes an x and y argument supplied by the System.Windows.Forms.DataGrid control's DragDrop, DragEnter, DragOver, MouseDown, MouseMove, MouseUp and MouseWheel events.

另请参阅

HitTest(Point) HitTest(Point) HitTest(Point) HitTest(Point)

获取有关使用特定 Point 的网格的信息(如网格中被单击点的行号和列号)。Gets information, such as row and column number of a clicked point on the grid, about the grid using a specific 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 Point Point Point

一个 Point,它代表单个 x,y 坐标。A Point that represents single x,y coordinate.

返回

一个 DataGrid.HitTestInfo,它包含有关该网格的特定信息。A DataGrid.HitTestInfo that contains specific information about the grid.

示例

下面的代码示例使用用户HitTest单击网格时发生的方法。The following code example uses the HitTest method in occurs when a user clicks on a grid.

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
 

注解

与控件的HitTest方法System.Windows.Forms.DataGrid一起使用, 以确定用户已单击控件的哪个部分。 DataGrid.HitTestInfo System.Windows.Forms.DataGridThe DataGrid.HitTestInfo, in conjunction with the HitTest method of the System.Windows.Forms.DataGrid control, is used to determine which part of a System.Windows.Forms.DataGrid control the user has clicked. DataGrid.HitTestInfo包含所单击的网格的行、列和部分。The DataGrid.HitTestInfo contains the row, column, and part of the grid that was clicked. 此外, Type属性DataGrid.HitTestType返回枚举。Additionally, the Type property returns a DataGrid.HitTestType enumeration.

DragDrop方法采用DragEnterMouseDown控件的、、 、、和MouseWheel事件提供的 x 和 y 参数。 MouseUp DragOver System.Windows.Forms.DataGrid HitTest MouseMoveThe HitTest method takes an x and y argument supplied by the System.Windows.Forms.DataGrid control's DragDrop, DragEnter, DragOver, MouseDown, MouseMove, MouseUp and MouseWheel events.

另请参阅

适用于