次の方法で共有


Font コンストラクタ (FontFamily, Single, FontStyle)

指定したサイズとスタイルを使用して、新しい Font を初期化します。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)

構文

'宣言
Public Sub New ( _
    family As FontFamily, _
    emSize As Single, _
    style As FontStyle _
)
'使用
Dim family As FontFamily
Dim emSize As Single
Dim style As FontStyle

Dim instance As New Font(family, emSize, style)
public Font (
    FontFamily family,
    float emSize,
    FontStyle style
)
public:
Font (
    FontFamily^ family, 
    float emSize, 
    FontStyle style
)
public Font (
    FontFamily family, 
    float emSize, 
    FontStyle style
)
public function Font (
    family : FontFamily, 
    emSize : float, 
    style : FontStyle
)

パラメータ

  • emSize
    新しいフォントの em サイズ (単位はポイント)。
  • style
    新しいフォントの FontStyle

例外

例外の種類 条件

ArgumentException

emSize が、0 以下であるか、無限大となるか、または有効な数値ではありません。

ArgumentNullException

family が null 参照 (Visual Basic では Nothing) です。

解説

結果として得られたフォントの Unit プロパティは Point に設定されます。

使用例

ボタンの Font プロパティを新しい太字スタイルの Font に設定する方法を次のコード例に示します。この例は、Button1 という名前のボタンを含んだ Windows フォームでの使用を意図してデザインされています。次のコードをフォームに貼り付け、Button1_Click メソッドをボタンの Click イベントに関連付けます。

 Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    If Not Button1.Font.Style = FontStyle.Bold Then
        Button1.Font = New Font(FontFamily.GenericSansSerif, _
            12.0F, FontStyle.Bold)
    End If
End Sub
private void Button1_Click(System.Object sender, System.EventArgs e)
{
    if (Button1.Font.Style != FontStyle.Bold)
            Button1.Font = new Font(FontFamily.GenericSansSerif,
            12.0F, FontStyle.Bold);
}
private:
   void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      Button1->Font = gcnew System::Drawing::Font( FontFamily::GenericSansSerif,12.0F,FontStyle::Bold );
   }
private void button1_Click(Object sender, System.EventArgs e)
{
    button1.set_Font(new Font(FontFamily.get_GenericSansSerif(), 12,
        FontStyle.Bold));
} //button1_Click

プラットフォーム

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

.NET Compact Framework

サポート対象 : 2.0、1.0

参照

関連項目

Font クラス
Font メンバ
System.Drawing 名前空間