Font.FromHfont(IntPtr) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates a Font from the specified Windows handle.
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
Parameters
- hfont
-
IntPtr
nativeint
A Windows handle to a GDI font.
Returns
The Font this method creates.
Exceptions
hfont
points to an object that is not a TrueType font.
Examples
The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e
, which is a parameter of the Paint event handler. The code performs the following actions:
Gets a handle to a GDI font.
Creates a Font from that handle.
Draws text to the screen, using the new Font.
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
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기