次の方法で共有


Font.ToHfont メソッド

この Font オブジェクトを識別するハンドルを返します。

Public Function ToHfont() As IntPtr
[C#]
public IntPtr ToHfont();
[C++]
public: IntPtr ToHfont();
[JScript]
public function ToHfont() : IntPtr;

戻り値

この Font オブジェクトを識別する Windows ハンドル。

解説

フォントの Unit プロパティが GraphicsUnit.Pixel 以外に設定されている場合、高さ (ピクセル単位) は、指定した垂直解像度を使用して計算されます。たとえば、フォント単位がインチ、フォント サイズが 0.3 であるとします。また、対応するフォント ファミリの em の高さが 2048、行間が 2355、指定した垂直解像度が 96 dpi の場合を想定すると、高さは次のように計算できます。

2355*(0.3/2048)*96 = 33.1171875

使用例

[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードでは、 Font オブジェクトを作成し、その Font オブジェクトを識別するハンドルを取得します。

 
Public Sub ToHfont_Example(e As PaintEventArgs)
' Create a Font object.
Dim myFont As New Font("Arial", 16)
' Get a handle to the Font object.
Dim hFont As IntPtr = myFont.ToHfont()
' Display a message box with the value of hFont.
MessageBox.Show(hFont.ToString())
End Sub
        
[C#] 
public void ToHfont_Example(PaintEventArgs e)
{
// Create a Font object.
Font myFont = new Font("Arial", 16);
// Get a handle to the Font object.
IntPtr hFont = myFont.ToHfont();
// Display a message box with the value of hFont.
MessageBox.Show(hFont.ToString());
}
        

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

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