DataGridViewRowPrePaintEventArgs.RowBounds DataGridViewRowPrePaintEventArgs.RowBounds DataGridViewRowPrePaintEventArgs.RowBounds DataGridViewRowPrePaintEventArgs.RowBounds Property

定義

現在の DataGridViewRow の境界を取得します。Get the bounds of the current 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 の境界を表す DataGridViewRowA Rectangle that represents the bounds of the current DataGridViewRow.

次のコード例は、使用する方法を示します、RowBoundsプロパティをカスタムの背景を描画する行の範囲を計算します。The following code example demonstrates how to use the RowBounds property to calculate the bounds of the row to paint a custom background. 変数、eの種類はDataGridViewRowPrePaintEventArgsします。The variable, e, is of type DataGridViewRowPrePaintEventArgs. このコード例で示されている例の一部は、方法。Windows フォームの DataGridView コントロール内の行の外観をカスタマイズします。This code example is part of a larger example provided in How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.

// 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します。The width of the RowBounds property is the same as the width of the DataGridView. 内の列の幅を取得する、DataGridViewを使用して、GetColumnsWidthメソッド。To get the width of the columns in the DataGridView, use the GetColumnsWidth method.

適用対象

こちらもご覧ください