DataGrid.GetCellBounds DataGrid.GetCellBounds DataGrid.GetCellBounds DataGrid.GetCellBounds Method

定义

获取指定某单元格四个角的 RectangleGets the Rectangle that specifies the four corners of a cell.

重载

GetCellBounds(Int32, Int32) GetCellBounds(Int32, Int32) GetCellBounds(Int32, Int32) GetCellBounds(Int32, Int32)

获取由行号和列号指定的单元格的 RectangleGets the Rectangle of the cell specified by row and column number.

GetCellBounds(DataGridCell) GetCellBounds(DataGridCell) GetCellBounds(DataGridCell) GetCellBounds(DataGridCell)

获取 Rectangle 所指定的单元格的 DataGridCellGets the Rectangle of the cell specified by DataGridCell.

GetCellBounds(Int32, Int32) GetCellBounds(Int32, Int32) GetCellBounds(Int32, Int32) GetCellBounds(Int32, Int32)

获取由行号和列号指定的单元格的 RectangleGets the Rectangle of the cell specified by row and column number.

public:
 System::Drawing::Rectangle GetCellBounds(int row, int col);
public System.Drawing.Rectangle GetCellBounds (int row, int col);
member this.GetCellBounds : int * int -> System.Drawing.Rectangle
Public Function GetCellBounds (row As Integer, col As Integer) As Rectangle

参数

row
Int32 Int32 Int32 Int32

单元格的行号。The number of the cell's row.

col
Int32 Int32 Int32 Int32

单元格的列号。The number of the cell's column.

返回

一个 Rectangle,它定义当前单元格的角。A Rectangle that defines the current cell's corners.

示例

下面的代码示例使用GetCellBounds方法Rectangle返回指定单元格的。The following code example uses the GetCellBounds method to return a Rectangle of a specified cell.

private:
   void dataGrid1_MouseDown( Object^ sender, MouseEventArgs^ e )
   {
      
      // Use the HitTest method to get a HitTestInfo object.
      System::Windows::Forms::DataGrid::HitTestInfo^ hi;
      DataGrid^ grid = dynamic_cast<DataGrid^>(sender);
      hi = grid->HitTest( e->X, e->Y );
      
      // Test if the clicked area was a cell.
      if ( hi->Type == DataGrid::HitTestType::Cell )
      {
         
         // If it's a cell, get the GridTable and CurrencyManager of the
         // clicked table.
         DataGridTableStyle^ dgt = dataGrid1->TableStyles[ 0 ];
         CurrencyManager^ myCurrencyManager = dynamic_cast<CurrencyManager^>(BindingContext[ myDataSet->Tables[ dataGrid1->DataMember ] ]);
         
         // Get the Rectangle of the clicked cell.
         Rectangle cellRect;
         cellRect = grid->GetCellBounds( hi->Row, hi->Column );
         
         // Get the clicked DataGridTextBoxColumn.
         DataGridTextBoxColumn^ gridCol = dynamic_cast<DataGridTextBoxColumn^>(dgt->GridColumnStyles[ hi->Column ]);
         
         // Insert code to edit the value.
      }
   }

private void dataGrid1_MouseDown(object sender, MouseEventArgs e){
   // Use the HitTest method to get a HitTestInfo object.
   System.Windows.Forms.DataGrid.HitTestInfo hi;   
   DataGrid grid = (DataGrid) sender;
   hi=grid.HitTest(e.X, e.Y);
   // Test if the clicked area was a cell.
   if(hi.Type==DataGrid.HitTestType.Cell ) {
      // If it's a cell, get the GridTable and CurrencyManager of the
      // clicked table.         
      DataGridTableStyle dgt = dataGrid1.TableStyles[0];     
      CurrencyManager myCurrencyManager = 
      (CurrencyManager)this.BindingContext
      [myDataSet.Tables[dataGrid1.DataMember]];
      // Get the Rectangle of the clicked cell.
      Rectangle cellRect;
      cellRect=grid.GetCellBounds(hi.Row, hi.Column);
      // Get the clicked DataGridTextBoxColumn.
      DataGridTextBoxColumn gridCol =
      (DataGridTextBoxColumn) dgt.GridColumnStyles[hi.Column];
      // Insert code to edit the value.
      
   }
}

    Private Sub dataGrid1_MouseDown _
(ByVal sender As Object, ByVal e As MouseEventArgs)
        ' Use the HitTest method to get a HitTestInfo object.
        Dim hi As System.Windows.Forms.DataGrid.HitTestInfo
        Dim grid As DataGrid = CType(sender, DataGrid)
        hi = grid.HitTest(e.X, e.Y)
        ' Test if the clicked area was a cell.
        If hi.Type = DataGrid.HitTestType.Cell Then
            ' If it's a cell, get the GridTable and CurrencyManager of the
            ' clicked table.         
            Dim dgt As DataGridTableStyle = dataGrid1.TableStyles(0)
            Dim myCurrencyManager As CurrencyManager = _
            CType(Me.BindingContext _
            (myDataSet.Tables(dataGrid1.DataMember)), CurrencyManager)
            ' Get the Rectangle of the clicked cell.
            Dim cellRect As Rectangle
            cellRect = grid.GetCellBounds(hi.Row, hi.Column)
            ' Get the clicked DataGridTextBoxColumn.
            Dim gridCol As DataGridTextBoxColumn = _
            CType(dgt.GridColumnStyles(hi.Column), DataGridTextBoxColumn)
            ' Insert code to dit the value.
        End If
    End Sub

注解

若要检索当前选定单元格的单元格边界, GetCurrentCellBounds请使用。To retrieve the cell bounds for the currently selected cell, use GetCurrentCellBounds.

另请参阅

GetCellBounds(DataGridCell) GetCellBounds(DataGridCell) GetCellBounds(DataGridCell) GetCellBounds(DataGridCell)

获取 Rectangle 所指定的单元格的 DataGridCellGets the Rectangle of the cell specified by DataGridCell.

public:
 System::Drawing::Rectangle GetCellBounds(System::Windows::Forms::DataGridCell dgc);
public System.Drawing.Rectangle GetCellBounds (System.Windows.Forms.DataGridCell dgc);
member this.GetCellBounds : System.Windows.Forms.DataGridCell -> System.Drawing.Rectangle
Public Function GetCellBounds (dgc As DataGridCell) As Rectangle

参数

返回

一个 Rectangle,它定义当前单元格的角。A Rectangle that defines the current cell's corners.

示例

下面的代码示例使用GetCellBounds方法Rectangle返回指定单元格的。The following code example uses the GetCellBounds method to return a Rectangle of a specified cell.

protected:
   DataGridCell dgc;

   void GetRect()
   {
      Rectangle rect;
      dgc.ColumnNumber = 0;
      dgc.RowNumber = 0;
      rect = dataGrid1->GetCellBounds( dgc );
      Console::WriteLine( rect );
   }
protected DataGridCell dgc;

protected void GetRect(){
    Rectangle rect;
    dgc.ColumnNumber = 0;
    dgc.RowNumber = 0;
    rect = dataGrid1.GetCellBounds(dgc);
    Console.WriteLine(rect.ToString());
 }
 
Private Sub GetRect()
    Dim rect As Rectangle
    Dim dgc As DataGridCell
    dgc.ColumnNumber = 0
    dgc.RowNumber = 0
    rect = DataGrid1.GetCellBounds(dgc)
    Console.WriteLine(rect.ToString())
 End Sub
 
另请参阅

适用于