Font.FromHfont(IntPtr) Metodo

Definizione

Crea un Font dall'handle di Windows specificato.

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

Parametri

hfont
IntPtr

Handle di Windows per un tipo di carattere GDI.

Restituisce

Il Font questo metodo crea.

Eccezioni

hfont punta a un oggetto che non è un tipo di carattere TrueType.

Esempio

L'esempio di codice seguente è progettato per l'uso con Windows Form e richiede PaintEventArgse, che è un parametro del gestore eventi Paint. Il codice esegue le azioni seguenti:

  • Ottiene un handle per un tipo di carattere GDI.

  • Crea un Font da tale handle.

  • Disegna testo sullo schermo usando il nuovo Font.

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

Si applica a

Prodotto Versioni
.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