DataGrid.HitTestInfo.Type DataGrid.HitTestInfo.Type DataGrid.HitTestInfo.Type DataGrid.HitTestInfo.Type Property

定义

获取 DataGrid 控件中被单击的部分(不包括行或列)。Gets the part of the DataGrid control, other than the row or column, that was clicked.

public:
 property System::Windows::Forms::DataGrid::HitTestType Type { System::Windows::Forms::DataGrid::HitTestType get(); };
public System.Windows.Forms.DataGrid.HitTestType Type { get; }
member this.Type : System.Windows.Forms.DataGrid.HitTestType
Public ReadOnly Property Type As DataGrid.HitTestType

属性值

示例

下面的示例通过调用打印被单击的部分的网格HitTest方法中的MouseDown事件的System.Windows.Forms.DataGrid控件。The following example prints the clicked part of the grid by calling the HitTest method from within the MouseDown event of a System.Windows.Forms.DataGrid control. 这将返回DataGrid.HitTestInfo对象。This returns a DataGrid.HitTestInfo object.

private:
   void dataGrid1_MouseDown( Object^ /*sender*/,
      System::Windows::Forms::MouseEventArgs^ e )
   {
      String^ newLine = "\n";
      Console::WriteLine( newLine );
      System::Windows::Forms::DataGrid::HitTestInfo^ myHitTest;
      // Use the DataGrid control's HitTest method with the x and y properties.
      myHitTest = dataGrid1->HitTest( e->X, e->Y );
      Console::WriteLine( "Hit {0}", ReturnHitTest( myHitTest->Type ) );
   }

   String^ ReturnHitTest(
      System::Windows::Forms::DataGrid::HitTestType hit )
   {
      // Use this function to return the part of the grid clicked.   
      switch ( hit )
      {
      case(System::Windows::Forms::DataGrid::HitTestType::Cell):
         return "Cell";
       
      case(System::Windows::Forms::DataGrid::HitTestType::Caption):
         return "Caption";
       
      case(System::Windows::Forms::DataGrid::HitTestType::ColumnHeader):
         return "ColumnHeader";
          
      case(System::Windows::Forms::DataGrid::HitTestType::ColumnResize):
         return "Resize";
          
      case(System::Windows::Forms::DataGrid::HitTestType::ParentRows):
         return "ParentRows";
          
      case(System::Windows::Forms::DataGrid::HitTestType::RowHeader):
         return "RowHeader";
          
      case(System::Windows::Forms::DataGrid::HitTestType::RowResize):
         return "RowResize";
          
      case(System::Windows::Forms::DataGrid::HitTestType::None):
         return "None";

      default:
         return "Unknown";
      }
   }
private void dataGrid1_MouseDown
(object sender, System.Windows.Forms.MouseEventArgs e)
{
   string newLine = "\n";
   Console.WriteLine(newLine);
   System.Windows.Forms.DataGrid.HitTestInfo myHitTest;
   // Use the DataGrid control's HitTest method with the x and y properties.
   myHitTest = dataGrid1.HitTest(e.X,e.Y);
   Console.WriteLine("Hit " + ReturnHitTest(myHitTest.Type ));
}
 
private string ReturnHitTest
(System.Windows.Forms.DataGrid.HitTestType hit)
{
   // Use this function to return the part of the grid clicked.   
   switch(hit) 
   {
      case(System.Windows.Forms.DataGrid.HitTestType.Cell):
         return "Cell";
       
      case(System.Windows.Forms.DataGrid.HitTestType.Caption):
         return "Caption";
       
      case(System.Windows.Forms.DataGrid.HitTestType.ColumnHeader):
         return "ColumnHeader";
          
      case(System.Windows.Forms.DataGrid.HitTestType.ColumnResize):
         return "Resize";
          
      case(System.Windows.Forms.DataGrid.HitTestType.ParentRows):
         return "ParentRows";
          
      case(System.Windows.Forms.DataGrid.HitTestType.RowHeader):
         return "RowHeader";
          
      case(System.Windows.Forms.DataGrid.HitTestType.RowResize):
         return "RowResize";
          
      case(System.Windows.Forms.DataGrid.HitTestType.None):
         return "None";

      default:return "Unknown";
   }
}
   
Private Sub dataGrid1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    Dim newLine As String = ControlChars.Cr
    Console.WriteLine(newLine)
    Dim myHitTest As System.Windows.Forms.DataGrid.HitTestInfo
    ' Use the DataGrid control's HitTest method with the x and y properties.
    myHitTest = dataGrid1.HitTest(e.X, e.Y)
    Console.WriteLine(("Hit " & ReturnHitTest(myHitTest.Type)))
End Sub 'dataGrid1_MouseDown


Private Function ReturnHitTest(hit As System.Windows.Forms.DataGrid.HitTestType) As String
    ' Use this function to return the part of the grid clicked.   
    Select Case hit
        Case System.Windows.Forms.DataGrid.HitTestType.Cell
                Return "Cell"
        
        Case System.Windows.Forms.DataGrid.HitTestType.Caption
                Return "Caption"
        
        Case System.Windows.Forms.DataGrid.HitTestType.ColumnHeader
                Return "ColumnHeader"
        
        Case System.Windows.Forms.DataGrid.HitTestType.ColumnResize
                Return "Resize"
        
        Case System.Windows.Forms.DataGrid.HitTestType.ParentRows
                Return "ParentRows"
        
        Case System.Windows.Forms.DataGrid.HitTestType.RowHeader
                Return "RowHeader"
        
        Case System.Windows.Forms.DataGrid.HitTestType.RowResize
                Return "RowResize"
        
        Case System.Windows.Forms.DataGrid.HitTestType.None
                Return "None"
        
        Case Else
                Return "Unknown"
    End Select
End Function 'ReturnHitTest

适用于

另请参阅