DataGridView.RowHeadersWidth 속성

정의

행 머리글이 포함된 열의 너비(픽셀)를 가져오거나 설정합니다.Gets or sets the width, in pixels, of the column that contains the row headers.

public:
 property int RowHeadersWidth { int get(); void set(int value); };
public int RowHeadersWidth { get; set; }
member this.RowHeadersWidth : int with get, set
Public Property RowHeadersWidth As Integer

속성 값

행 머리글이 포함된 열의 너비(픽셀)입니다.The width, in pixels, of the column that contains row headers. 기본값은 43입니다.The default is 43.

예외

이 속성을 설정할 때 지정된 값이 최소 너비인 4픽셀보다 작거나 최대 너비인 32768픽셀보다 큰 경우The specified value when setting this property is less than the minimum width of 4 pixels or is greater than the maximum width of 32768 pixels.

예제

다음 코드 예제에서는 행 그리기 시나리오에서 RowHeadersWidth 속성을 사용 하는 방법을 보여 줍니다.The following code example illustrates how to use the RowHeadersWidth property in a row-painting scenario. 예제에서는이 속성의 값이 있는 사용자 지정 배경을 그릴 범위를 계산 하 사용 됩니다.In the example, the value of this property is used to calculate the bounds within which a custom background is drawn.

이 코드는방법: DataGridView 컨트롤 Windows Forms의 행 모양 사용자 지정에서 사용할 수 있는 더 큰 예제의 일부입니다.This code is part of a larger example available inHow to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.

// Paints the custom selection background for selected rows.
void dataGridView1_RowPrePaint(object sender,
        DataGridViewRowPrePaintEventArgs e)
{
    // Do not automatically paint the focus rectangle.
    e.PaintParts &= ~DataGridViewPaintParts.Focus;

    // 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);
        }
    }
}
' Paints the custom selection background for selected rows.
Sub dataGridView1_RowPrePaint(ByVal sender As Object, _
    ByVal e As DataGridViewRowPrePaintEventArgs) _
    Handles dataGridView1.RowPrePaint

    ' Do not automatically paint the focus rectangle.
    e.PaintParts = e.PaintParts And Not DataGridViewPaintParts.Focus

    ' 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

End Sub

설명

RowHeadersWidth 속성을 사용 하 여 행 머리글 열의 크기를 지정 된 너비로 조정할 수 있습니다.The RowHeadersWidth property can be used to resize the row header column to a specified width. 행 머리글 셀의 내용에 맞게이 열의 너비를 조정 하려면 AutoResizeRowHeadersWidth 메서드를 사용 합니다.To adjust the width of this column to fit the contents of the row header cells, use the AutoResizeRowHeadersWidth method.

적용 대상

추가 정보