Font.FromHfont(IntPtr) Methode
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Erstellt eine Font aus dem angegebenen 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
Parameter
- hfont
-
IntPtr
nativeint
Ein Windows-Handle für eine GDI-Schriftart.
Gibt zurück
Die Font, die von dieser Methode erstellt wird.
Ausnahmen
hfont
zeigt auf ein Objekt, das keine TrueType-Schriftart ist.
Beispiele
Das folgende Codebeispiel ist für die Verwendung mit Windows Forms konzipiert und erfordert PaintEventArgse
, was ein Parameter des Paint Ereignishandlers ist. Der Code führt die folgenden Aktionen aus:
Ruft ein Handle für eine GDI-Schriftart ab.
Erstellt ein Font aus diesem Handle.
Zeichnet Text auf den Bildschirm, wobei der neue Fontverwendet wird.
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
Gilt für:
Feedback
https://aka.ms/ContentUserFeedback.
Bald verfügbar: Im Laufe des Jahres 2024 werden wir GitHub-Issues stufenweise als Feedbackmechanismus für Inhalte abbauen und durch ein neues Feedbacksystem ersetzen. Weitere Informationen finden Sie unterFeedback senden und anzeigen für