Lire en anglais

Partager via


Font.FromHfont(IntPtr) Méthode

Définition

Crée un Font à partir du handle Windows spécifié.

public static System.Drawing.Font FromHfont (IntPtr hfont);

Paramètres

hfont
IntPtr

Handle Windows vers une police GDI.

Retours

La Font cette méthode crée.

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 gestionnaire d’événements Paint. Le code effectue les actions suivantes :

  • Obtient un handle vers une police GDI.

  • Crée un Font à partir de ce handle.

  • Dessine du texte à l’écran à l’aide du nouveau Font.

[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);
}

S’applique à

Produit Versions
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9