Font.FromHfont(IntPtr) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Crée un Font à partir du handle Windows spécifié.
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
Paramètres
- hfont
-
IntPtr
nativeint
Handle Windows dans une police GDI.
Retours
Font créé par cette méthode.
Exceptions
hfont
pointe vers un objet qui n'est pas une police TrueType.
Exemples
L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse
, qui est un paramètre du Paint gestionnaire d’événements. Le code effectue les actions suivantes :
Obtient un handle pour une police GDI.
Crée un Font à partir de ce handle.
Dessine le texte vers l’écran, à l’aide du nouveau 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
S’applique à
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour