DataGrid.GetCellBounds 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 Rectangle,指定儲存格四個端點。
多載
GetCellBounds(Int32, Int32) |
取得資料列和資料行編號所指定的儲存格 Rectangle。 |
GetCellBounds(DataGridCell) |
取得 Rectangle 指定之儲存格的 DataGridCell。 |
GetCellBounds(Int32, Int32)
取得資料列和資料行編號所指定的儲存格 Rectangle。
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
儲存格的資料列編號。
- col
- Int32
儲存格的資料行編號。
傳回
Rectangle,定義目前儲存格的四個端點。
範例
下列程式碼範例會 GetCellBounds 使用 方法傳回 Rectangle 指定儲存格的 。
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 。
另請參閱
適用於
GetCellBounds(DataGridCell)
取得 Rectangle 指定之儲存格的 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
參數
- dgc
- DataGridCell
要查詢的 DataGridCell。
傳回
Rectangle,定義目前儲存格的四個端點。
範例
下列程式碼範例會 GetCellBounds 使用 方法傳回 Rectangle 指定儲存格的 。
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