Font.ToHfont Metodo

Definizione

Restituisce un handle per questo oggetto Font.

public:
 IntPtr ToHfont();
public IntPtr ToHfont ();
member this.ToHfont : unit -> nativeint
Public Function ToHfont () As IntPtr

Restituisce

IntPtr

nativeint

Handle Windows per questo oggetto Font.

Eccezioni

L'operazione è stata completata.

Esempio

L'esempio di codice seguente crea un Font oggetto e quindi ottiene un handle per tale Fontoggetto . L'esempio è progettato per l'uso con Windows Forms e richiede PaintEventArgse, ovvero un parametro del Paint gestore eventi.

   //Reference the GDI DeleteObject method.
public:
   [System::Runtime::InteropServices::DllImport("GDI32.dll")]
   static bool DeleteObject( IntPtr objectHandle );
   void ToHfont_Example( PaintEventArgs^ /*e*/ )
   {
      // Create a Font object.
      System::Drawing::Font^ myFont = gcnew System::Drawing::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 );
   }

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

' Reference the DeleteObject method in the GDI library.
<System.Runtime.InteropServices.DllImportAttribute("GDI32.DLL")> _
Private Shared Function DeleteObject(ByVal objectHandle As IntPtr) As Boolean
End Function

Public Sub ToHfont_Example(ByVal e As PaintEventArgs)

    ' Create a Font object.
    Dim myFont As New Font("Arial", 16)

    ' Get a handle to the Font object.
    Dim hFont As IntPtr = myFont.ToHfont()

    ' Display a message box with the value of hFont.
    MessageBox.Show(hFont.ToString())

    ' Dispose of the hFont.
    DeleteObject(hFont)
End Sub

Commenti

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

Si applica a