DataGridView.Font 속성

정의

DataGridView에서 표시되는 텍스트의 글꼴을 가져오거나 설정합니다.

public:
 virtual property System::Drawing::Font ^ Font { System::Drawing::Font ^ get(); void set(System::Drawing::Font ^ value); };
[System.ComponentModel.Browsable(false)]
public override System.Drawing.Font Font { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.Font : System.Drawing.Font with get, set
Public Overrides Property Font As Font

속성 값

Font

컨트롤에 표시되는 텍스트에 적용되는 Font입니다. 기본값은 DefaultFont 속성 값입니다.

특성

예제

다음 코드 예제에서는이 속성의 사용을 보여 줍니다. 이 예제는 방법: 언바운드 Windows Forms DataGridView 컨트롤 만들기에서 사용할 수 있는 더 큰 예제의 일부입니다.

private void SetupDataGridView()
{
    this.Controls.Add(songsDataGridView);

    songsDataGridView.ColumnCount = 5;

    songsDataGridView.ColumnHeadersDefaultCellStyle.BackColor = Color.Navy;
    songsDataGridView.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
    songsDataGridView.ColumnHeadersDefaultCellStyle.Font =
        new Font(songsDataGridView.Font, FontStyle.Bold);

    songsDataGridView.Name = "songsDataGridView";
    songsDataGridView.Location = new Point(8, 8);
    songsDataGridView.Size = new Size(500, 250);
    songsDataGridView.AutoSizeRowsMode =
        DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
    songsDataGridView.ColumnHeadersBorderStyle =
        DataGridViewHeaderBorderStyle.Single;
    songsDataGridView.CellBorderStyle = DataGridViewCellBorderStyle.Single;
    songsDataGridView.GridColor = Color.Black;
    songsDataGridView.RowHeadersVisible = false;

    songsDataGridView.Columns[0].Name = "Release Date";
    songsDataGridView.Columns[1].Name = "Track";
    songsDataGridView.Columns[2].Name = "Title";
    songsDataGridView.Columns[3].Name = "Artist";
    songsDataGridView.Columns[4].Name = "Album";
    songsDataGridView.Columns[4].DefaultCellStyle.Font =
        new Font(songsDataGridView.DefaultCellStyle.Font, FontStyle.Italic);

    songsDataGridView.SelectionMode =
        DataGridViewSelectionMode.FullRowSelect;
    songsDataGridView.MultiSelect = false;
    songsDataGridView.Dock = DockStyle.Fill;

    songsDataGridView.CellFormatting += new
        DataGridViewCellFormattingEventHandler(
        songsDataGridView_CellFormatting);
}
Private Sub SetupDataGridView()

    Me.Controls.Add(songsDataGridView)

    songsDataGridView.ColumnCount = 5
    With songsDataGridView.ColumnHeadersDefaultCellStyle
        .BackColor = Color.Navy
        .ForeColor = Color.White
        .Font = New Font(songsDataGridView.Font, FontStyle.Bold)
    End With

    With songsDataGridView
        .Name = "songsDataGridView"
        .Location = New Point(8, 8)
        .Size = New Size(500, 250)
        .AutoSizeRowsMode = _
            DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
        .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
        .CellBorderStyle = DataGridViewCellBorderStyle.Single
        .GridColor = Color.Black
        .RowHeadersVisible = False

        .Columns(0).Name = "Release Date"
        .Columns(1).Name = "Track"
        .Columns(2).Name = "Title"
        .Columns(3).Name = "Artist"
        .Columns(4).Name = "Album"
        .Columns(4).DefaultCellStyle.Font = _
            New Font(Me.songsDataGridView.DefaultCellStyle.Font, FontStyle.Italic)

        .SelectionMode = DataGridViewSelectionMode.FullRowSelect
        .MultiSelect = False
        .Dock = DockStyle.Fill
    End With

End Sub

설명

Font 속성은 앰비언트 속성입니다. 앰비언트 속성은 설정되지 않은 경우 부모 컨트롤에서 검색되는 컨트롤 속성입니다. 예를 들어 a Button 는 기본적으로 부모와 Form 동일합니다BackColor. 앰비언트 속성에 대한 자세한 내용은 클래스 또는 클래스 개요를 Control 참조 AmbientProperties 하세요.

Font 변경할 수 없으므로(해당 속성을 조정할 수 없음) 속성에 새 Font 개체만 할당할 Font 수 있습니다. 그러나 기존 글꼴에 새 글꼴을 기반으로 할 수 있습니다.

컨트롤은 DataGridView 속성 값을 Font , ColumnHeadersDefaultCellStyleRowHeadersDefaultCellStyle 속성에서 반환하는 DefaultCellStyle개체 속성의 DataGridViewCellStyle 기본값 Font 으로 사용합니다. 값을 변경하면 Font , ColumnHeadersDefaultCellStyle및 속성이 자동으로 업데이트DefaultCellStyle되고 RowHeadersDefaultCellStyle 값을 상속하는 셀의 글꼴이 변경됩니다. 머리글 셀은 기본적으로 값을 재정의하며 특정 행, 열 및 셀의 값을 재정의할 수 있습니다. 셀 스타일 상속에 대한 자세한 내용은 Windows Forms DataGridView 컨트롤의 셀 스타일을 참조하세요.

적용 대상

추가 정보