Font.FromHfont(IntPtr) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從指定的 Windows 句柄建立 Font。
public:
static System::Drawing::Font ^ FromHfont(IntPtr hfont);
public static System.Drawing.Font FromHfont (IntPtr hfont);
static member FromHfont : nativeint -> System.Drawing.Font
Public Shared Function FromHfont (hfont As IntPtr) As Font
參數
- hfont
-
IntPtr
nativeint
GDI 字型的 Windows 句柄。
傳回
此方法所建立 Font。
例外狀況
hfont
指向不是 TrueType 字型的物件。
範例
下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 PaintEventArgse
,這是 Paint 事件處理程式的參數。 程式代碼會執行下列動作:
private:
[System::Runtime::InteropServices::DllImportAttribute("gdi32.dll")]
static IntPtr GetStockObject( int fnObject );
public:
void FromHfont_Example( PaintEventArgs^ e )
{
// Get a handle for a GDI font.
IntPtr hFont = GetStockObject( 17 );
// Create a Font object from hFont.
System::Drawing::Font^ hfontFont = System::Drawing::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 );
}
[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);
}
<System.Runtime.InteropServices.DllImportAttribute("GDI32.DLL")> _
Private Shared Function GetStockObject(ByVal fnObject As Integer) As IntPtr
End Function
Public Sub FromHfont_Example(ByVal e As PaintEventArgs)
' Get a handle for a GDI font.
Dim hFont As IntPtr = GetStockObject(17)
' 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