DataGridViewRowPrePaintEventArgs.RowBounds Vlastnost

Definice

Získá hranice aktuálního 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

Hodnota vlastnosti

A Rectangle , který představuje hranice aktuálního DataGridViewRowobjektu .

Příklady

Následující příklad kódu ukazuje, jak použít RowBounds vlastnost k výpočtu hranic řádku k vykreslení vlastní pozadí. Proměnná eje typu DataGridViewRowPrePaintEventArgs. Tento příklad kódu je součástí většího příkladu v části Postupy: Přizpůsobení vzhledu řádků v ovládacím prvku model Windows Forms DataGridView.

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

Poznámky

Šířka RowBounds vlastnosti je stejná jako šířka objektu DataGridView. Pokud chcete získat šířku sloupců v DataGridView, použijte metodu GetColumnsWidth .

Platí pro

Viz také