Font.ToHfont Metodo

Definizione

Restituisce un handle per questo Font.

C#
public IntPtr ToHfont();

Restituisce

IntPtr

Handle di Windows per questo Font.

Eccezioni

Operazione non riuscita.

Esempio

Nell'esempio di codice seguente viene creato un Font e quindi viene creato un handle per tale Font. L'esempio è progettato per l'uso con Windows Form e richiede PaintEventArgse, che è un parametro del gestore eventi Paint.

C#

//Reference the GDI DeleteObject method.
    [System.Runtime.InteropServices.DllImport("GDI32.dll")]
    public static extern bool DeleteObject(IntPtr objectHandle); 

    public void ToHfont_Example(PaintEventArgs e)
    {
        // Create a Font object.
        Font myFont = new Font("Arial", 16);
                 
        // Get a handle to the Font object.
        IntPtr hFont = myFont.ToHfont();
                 
        // Display a message box with the value of hFont.
        MessageBox.Show(hFont.ToString());
        
        //Dispose of the hFont.
        DeleteObject(hFont);
    }

Commenti

Quando si usa questo metodo, è necessario eliminare i Hfont risultanti usando il metodo di DeleteObject GDI per assicurarsi che le risorse vengano rilasciate.

Si applica a

Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.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 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10