DataGridView.Font プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGridView.Font プロパティの意味・解説 

DataGridView.Font プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

DataGridView によって表示されるテキストのフォントを取得または設定します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

解説解説

Font プロパティがアンビエント プロパティです。アンビエント プロパティは、コントロール プロパティです。設定しない場合は、親コントロールから取得されます。たとえば、Button は、既定では親の Form と同じ BackColor を持ちます。アンビエント プロパティの詳細については、AmbientProperties クラスまたは Control クラスの概要を参照してください。

Font は変更不可で、プロパティをまったく調整できないため、Font プロパティには新しい Font オブジェクトの割り当てのみが可能です。ただし、既存のフォントをベースにして新しいフォントを設定できます。

DataGridView コントロールは、DefaultCellStyle、ColumnHeadersDefaultCellStyle、および RowHeadersDefaultCellStyle の各プロパティによって返される DataGridViewCellStyle オブジェクトの Font プロパティの既定値として、Font プロパティの値を使用します。Font 値を変更すると、DefaultCellStyle、ColumnHeadersDefaultCellStyle、および RowHeadersDefaultCellStyle の各プロパティが自動的に更新され、値を継承するすべてのセルのフォントが変更されます。ヘッダー セルは既定で値をオーバーライドするため、特定の行、列、およびセルの値をオーバーライドできます。セル スタイル継承の詳細については、「Windows フォーム DataGridView コントロールでのセルのスタイル」を参照してください。

使用例使用例

このプロパティの使用方法を示すコード例を次に示します。次の例は「方法 : 連結されていない Windows フォーム DataGridView コントロールを作成する」で取り上げている例の一部です。

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
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);
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridView クラス
DataGridView メンバ
System.Windows.Forms 名前空間
DataGridView.DefaultCellStyle プロパティ
DataGridView.ColumnHeadersDefaultCellStyle プロパティ
RowHeadersDefaultCellStyle
DataGridViewCellStyle
Font
Font
その他の技術情報
Windows フォーム DataGridView コントロールでのセルのスタイル
DataGridView コントロール (Windows フォーム)



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「DataGridView.Font プロパティ」の関連用語

DataGridView.Font プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataGridView.Font プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS