Font クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
フォントフェイス、サイズ、スタイル属性など、テキストの特定の形式を定義します。 このクラスは継承できません。
public ref class Font sealed : MarshalByRefObject, ICloneable, IDisposable, System::Runtime::Serialization::ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.FontConverter))]
[System.Serializable]
public sealed class Font : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.FontConverter))]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class Font : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.FontConverter))]
public sealed class Font : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter("System.Drawing.FontConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")]
public sealed class Font : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.FontConverter))>]
[<System.Serializable>]
type Font = class
inherit MarshalByRefObject
interface ICloneable
interface IDisposable
interface ISerializable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.FontConverter))>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Font = class
inherit MarshalByRefObject
interface ICloneable
interface ISerializable
interface IDisposable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.FontConverter))>]
type Font = class
inherit MarshalByRefObject
interface ICloneable
interface IDisposable
interface ISerializable
[<System.ComponentModel.TypeConverter("System.Drawing.FontConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")>]
type Font = class
inherit MarshalByRefObject
interface ICloneable
interface IDisposable
interface ISerializable
Public NotInheritable Class Font
Inherits MarshalByRefObject
Implements ICloneable, IDisposable, ISerializable
- 継承
- 属性
- 実装
例
次のコード例では、 Font コンストラクターと、 Size、 SizeInPoints、および Unit プロパティを使用する方法を示します。 この例は、文字列 "Bigger" と "Smaller" が設定された ComboBox1 という名前のComboBoxと、Label1という名前のLabelを含む Windows フォームで使用するように設計されています。 次のコードをフォームに貼り付け、ComboBox1_SelectedIndexChanged メソッドをComboBox コントロールのSelectedIndexChanged イベントに関連付けます。
private:
void ComboBox1_SelectedIndexChanged(System::Object^ sender,
System::EventArgs^ e)
{
// Cast the sender object back to a ComboBox.
ComboBox^ ComboBox1 = (ComboBox^) sender;
// Retrieve the selected item.
String^ selectedString = (String^) ComboBox1->SelectedItem;
// Convert it to lowercase.
selectedString = selectedString->ToLower();
// Declare the current size.
float currentSize;
// If Bigger is selected, get the current size from the
// Size property and increase it. Reset the font to the
// new size, using the current unit.
if (selectedString == "bigger")
{
currentSize = Label1->Font->Size;
currentSize += 2.0F;
Label1->Font =gcnew System::Drawing::Font(Label1->Font->Name,
currentSize, Label1->Font->Style, Label1->Font->Unit);
}
// If Smaller is selected, get the current size, in
// points, and decrease it by 2. Reset the font with
// the new size in points.
if (selectedString == "smaller")
{
currentSize = Label1->Font->Size;
currentSize -= 2.0F;
Label1->Font = gcnew System::Drawing::Font(Label1->Font->Name,
currentSize, Label1->Font->Style);
}
}
private void ComboBox1_SelectedIndexChanged(System.Object sender,
System.EventArgs e)
{
// Cast the sender object back to a ComboBox.
ComboBox ComboBox1 = (ComboBox) sender;
// Retrieve the selected item.
string selectedString = (string) ComboBox1.SelectedItem;
// Convert it to lowercase.
selectedString = selectedString.ToLower();
// Declare the current size.
float currentSize;
// Switch on the selected item.
switch(selectedString)
{
// If Bigger is selected, get the current size from the
// Size property and increase it. Reset the font to the
// new size, using the current unit.
case "bigger":
currentSize = Label1.Font.Size;
currentSize += 2.0F;
Label1.Font = new Font(Label1.Font.Name, currentSize,
Label1.Font.Style, Label1.Font.Unit);
// If Smaller is selected, get the current size, in points,
// and decrease it by 1. Reset the font with the new size
// in points.
break;
case "smaller":
currentSize = Label1.Font.SizeInPoints;
currentSize -= 1;
Label1.Font = new Font(Label1.Font.Name, currentSize,
Label1.Font.Style);
break;
}
}
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
' Cast the sender object back to a ComboBox.
Dim ComboBox1 As ComboBox = CType(sender, ComboBox)
' Retrieve the selected item.
Dim selectedString As String = CType(ComboBox1.SelectedItem, String)
' Convert it to lowercase.
selectedString = selectedString.ToLower()
' Declare the current size.
Dim currentSize As Single
' Switch on the selected item.
Select Case selectedString
' If Bigger is selected, get the current size from the
' Size property and increase it. Reset the font to the
' new size, using the current unit.
Case "bigger"
currentSize = Label1.Font.Size
currentSize += 2.0F
Label1.Font = New Font(Label1.Font.Name, currentSize, _
Label1.Font.Style, Label1.Font.Unit)
' If Smaller is selected, get the current size, in points,
' and decrease it by 1. Reset the font with the new size
' in points.
Case "smaller"
currentSize = Label1.Font.SizeInPoints
currentSize -= 1
Label1.Font = New Font(Label1.Font.Name, currentSize, _
Label1.Font.Style)
End Select
End Sub
注釈
フォントの作成方法の詳細については、「 方法: フォント ファミリとフォントを構築する」を参照してください。 Windows フォーム アプリケーションは TrueType フォントをサポートしており、OpenType フォントのサポートは限られています。 サポートされていないフォントを使用しようとした場合、またはアプリケーションを実行しているコンピューターにフォントがインストールされていない場合は、Microsoft Sans Serif フォントが置き換えられます。
Note
.NET 6 以降のバージョンでは、この種類を含む System.Drawing.Common パッケージは、Windows オペレーティング システムでのみサポートされています。 クロスプラットフォーム アプリでこの種類を使用すると、コンパイル時の警告と実行時の例外が発生します。 詳細については、「System.Drawing.Common が Windows でしかサポートされない」を参照してください。
コンストラクター
| 名前 | 説明 |
|---|---|
| Font(Font, FontStyle) | |
| Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte, Boolean) |
指定したサイズ、スタイル、単位、および文字セットを使用して、新しい Font を初期化します。 |
| Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte) |
指定したサイズ、スタイル、単位、および文字セットを使用して、新しい Font を初期化します。 |
| Font(FontFamily, Single, FontStyle, GraphicsUnit) |
指定したサイズ、スタイル、および単位を使用して、新しい Font を初期化します。 |
| Font(FontFamily, Single, FontStyle) |
指定したサイズとスタイルを使用して、新しい Font を初期化します。 |
| Font(FontFamily, Single, GraphicsUnit) | |
| Font(FontFamily, Single) |
指定したサイズを使用して新しい Font を初期化します。 |
| Font(String, Single, FontStyle, GraphicsUnit, Byte, Boolean) |
指定したサイズ、スタイル、単位、および文字セットを使用して、新しい Font を初期化します。 |
| Font(String, Single, FontStyle, GraphicsUnit, Byte) |
指定したサイズ、スタイル、単位、および文字セットを使用して、新しい Font を初期化します。 |
| Font(String, Single, FontStyle, GraphicsUnit) |
指定したサイズ、スタイル、および単位を使用して、新しい Font を初期化します。 |
| Font(String, Single, FontStyle) |
指定したサイズとスタイルを使用して、新しい Font を初期化します。 |
| Font(String, Single, GraphicsUnit) | |
| Font(String, Single) |
指定したサイズを使用して新しい Font を初期化します。 |
プロパティ
| 名前 | 説明 |
|---|---|
| Bold |
この Font が太字かどうかを示す値を取得します。 |
| FontFamily |
このFontFamilyに関連付けられているFontを取得します。 |
| GdiCharSet |
この Font が使用する GDI 文字セットを指定するバイト値を取得します。 |
| GdiVerticalFont |
この Font が GDI 縦書きフォントから派生しているかどうかを示すブール値を取得します。 |
| Height |
このフォントの行間を取得します。 |
| IsSystemFont |
フォントが SystemFontsのメンバーであるかどうかを示す値を取得します。 |
| Italic |
このフォントに斜体のスタイルが適用されているかどうかを示す値を取得します。 |
| Name |
この Fontの顔名を取得します。 |
| OriginalFontName |
最初に指定されたフォントの名前を取得します。 |
| Size | |
| SizeInPoints |
この Fontの em サイズをポイント単位で取得します。 |
| Strikeout |
この Font がフォントの水平線を指定するかどうかを示す値を取得します。 |
| Style |
この Fontのスタイル情報を取得します。 |
| SystemFontName |
IsSystemFont プロパティが |
| Underline |
この Font に下線が付けられるかどうかを示す値を取得します。 |
| Unit |
この Fontの測定単位を取得します。 |
メソッド
| 名前 | 説明 |
|---|---|
| Clone() |
この Fontの正確なコピーを作成します。 |
| CreateObjRef(Type) |
リモート オブジェクトとの通信に使用されるプロキシの生成に必要なすべての関連情報を含むオブジェクトを作成します。 (継承元 MarshalByRefObject) |
| Dispose() |
この Fontで使用されているすべてのリソースを解放します。 |
| Equals(Object) |
指定したオブジェクトがFontであり、このFontと同じFontFamily、GdiVerticalFont、GdiCharSet、Style、Size、およびUnitプロパティ値を持っているかどうかを示します。 |
| Finalize() |
オブジェクトがガベージ コレクションによって解放される前に、リソースを解放し、その他のクリーンアップ操作を実行できるようにします。 |
| FromHdc(IntPtr) |
指定した Windows ハンドルからデバイス コンテキストへの Font を作成します。 |
| FromHfont(IntPtr) |
指定した Windows ハンドルから Font を作成します。 |
| FromLogFont(LOGFONT, IntPtr) |
フォントフェイス、サイズ、スタイル属性など、テキストの特定の形式を定義します。 このクラスは継承できません。 |
| FromLogFont(LOGFONT) |
フォントフェイス、サイズ、スタイル属性など、テキストの特定の形式を定義します。 このクラスは継承できません。 |
| FromLogFont(Object, IntPtr) |
指定した GDI 論理フォント ( |
| FromLogFont(Object) |
指定した GDI 論理フォント ( |
| GetHashCode() |
この Fontのハッシュ コードを取得します。 |
| GetHeight() |
このフォントの行間をピクセル単位で返します。 |
| GetHeight(Graphics) |
指定した Graphicsの現在の単位で、このフォントの行間を返します。 |
| GetHeight(Single) |
指定した垂直方向の解像度のデバイスに描画する場合に、この Font の高さをピクセル単位で返します。 |
| GetLifetimeService() |
古い.
このインスタンスの有効期間ポリシーを制御する現在の有効期間サービス オブジェクトを取得します。 (継承元 MarshalByRefObject) |
| GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
| InitializeLifetimeService() |
古い.
このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。 (継承元 MarshalByRefObject) |
| MemberwiseClone() |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
| MemberwiseClone(Boolean) |
現在の MarshalByRefObject オブジェクトの簡易コピーを作成します。 (継承元 MarshalByRefObject) |
| ToHfont() |
この Fontへのハンドルを返します。 |
| ToLogFont(LOGFONT, Graphics) |
フォントフェイス、サイズ、スタイル属性など、テキストの特定の形式を定義します。 このクラスは継承できません。 |
| ToLogFont(LOGFONT) |
フォントフェイス、サイズ、スタイル属性など、テキストの特定の形式を定義します。 このクラスは継承できません。 |
| ToLogFont(Object, Graphics) |
このFontから GDI 論理フォント ( |
| ToLogFont(Object) |
このFontから GDI 論理フォント ( |
| ToString() |
この Fontの人間が判読できる文字列形式を返します。 |
明示的なインターフェイスの実装
| 名前 | 説明 |
|---|---|
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
ターゲット オブジェクトをシリアル化するために必要なデータを SerializationInfo に設定します。 |