指定した Windows ハンドルから Font オブジェクトを作成します。
Public Shared Function FromHfont( _
ByVal hfont As IntPtr _) As Font
[C#]
public static Font FromHfont(IntPtrhfont);
[C++]
public: static Font* FromHfont(IntPtrhfont);
[JScript]
public static function FromHfont(
hfont : IntPtr) : Font;
パラメータ
- hfont
GDI フォントを識別する Windows ハンドル。
戻り値
このメソッドが作成する Font オブジェクト。
使用例
[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードは次のアクションを実行します。
<System.Runtime.InteropServices.DllImportAttribute("GDI32.DLL")> _
Private Shared Function GetStockObject(fnObject As Integer) As IntPtr
End Function
Public Sub FromHfont_Example(e As PaintEventArgs)
' Get a handle for a GDI font.
Dim hFont As IntPtr = GetStockObject(0)
' Create a Font object from hFont.
Dim hfontFont As Font = Font.FromHfont(hFont)
' Use hfontFont to draw text to the screen.
e.Graphics.DrawString("This font is from a GDI HFONT", hfontFont, _
Brushes.Black, 0, 0)
End Sub
[C#]
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern IntPtr GetStockObject(int fnObject);
public void FromHfont_Example(PaintEventArgs e)
{
// Get a handle for a GDI font.
IntPtr hFont = GetStockObject(0);
// Create a Font object from hFont.
Font hfontFont = Font.FromHfont(hFont);
// Use hfontFont to draw text to the screen.
e.Graphics.DrawString(
"This font is from a GDI HFONT",
hfontFont,
Brushes.Black,
0,
0);
}
[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 ファミリ