DataGridViewRowPrePaintEventArgs.RowBounds 屬性

定義

取得目前 DataGridViewRow 的界限。

public:
 property System::Drawing::Rectangle RowBounds { System::Drawing::Rectangle get(); };
public System.Drawing.Rectangle RowBounds { get; }
member this.RowBounds : System.Drawing.Rectangle
Public ReadOnly Property RowBounds As Rectangle

屬性值

Rectangle

Rectangle,表示目前 DataGridViewRow 的界限。

範例

下列程式碼範例示範如何使用 RowBounds 屬性來計算資料列的界限,以繪製自訂背景。 變數 的 eDataGridViewRowPrePaintEventArgs 別為 。 此程式碼範例是如何:自訂 DataGridView 控制項中 Windows Forms資料列外觀中提供之較大範例的一部分。

// Determine whether the cell should be painted
// with the custom selection background.
if ((e.State & DataGridViewElementStates.Selected) ==
            DataGridViewElementStates.Selected)
{
    // Calculate the bounds of the row.
    Rectangle rowBounds = new Rectangle(
        this.dataGridView1.RowHeadersWidth, e.RowBounds.Top,
        this.dataGridView1.Columns.GetColumnsWidth(
            DataGridViewElementStates.Visible) -
        this.dataGridView1.HorizontalScrollingOffset + 1,
        e.RowBounds.Height);

    // Paint the custom selection background.
    using (Brush backbrush =
        new System.Drawing.Drawing2D.LinearGradientBrush(rowBounds,
            this.dataGridView1.DefaultCellStyle.SelectionBackColor,
            e.InheritedRowStyle.ForeColor,
            System.Drawing.Drawing2D.LinearGradientMode.Horizontal))
    {
        e.Graphics.FillRectangle(backbrush, rowBounds);
    }
}
' Determine whether the cell should be painted with the 
' custom selection background.
If (e.State And DataGridViewElementStates.Selected) = _
    DataGridViewElementStates.Selected Then

    ' Calculate the bounds of the row.
    Dim rowBounds As New Rectangle( _
        Me.dataGridView1.RowHeadersWidth, e.RowBounds.Top, _
        Me.dataGridView1.Columns.GetColumnsWidth( _
        DataGridViewElementStates.Visible) - _
        Me.dataGridView1.HorizontalScrollingOffset + 1, _
        e.RowBounds.Height)

    ' Paint the custom selection background.
    Dim backbrush As New _
        System.Drawing.Drawing2D.LinearGradientBrush(rowBounds, _
        Me.dataGridView1.DefaultCellStyle.SelectionBackColor, _
        e.InheritedRowStyle.ForeColor, _
        System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
    Try
        e.Graphics.FillRectangle(backbrush, rowBounds)
    Finally
        backbrush.Dispose()
    End Try
End If

備註

屬性的 RowBounds 寬度與 的 DataGridView 寬度相同。 若要取得 中 DataGridView 資料行的寬度,請使用 GetColumnsWidth 方法。

適用於

另請參閱