Freigeben über


Font.ToHfont-Methode

Gibt ein Handle für dieses Font-Objekt zurück.

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

Syntax

'Declaration
Public Function ToHfont As IntPtr
'Usage
Dim instance As Font
Dim returnValue As IntPtr

returnValue = instance.ToHfont
public IntPtr ToHfont ()
public:
IntPtr ToHfont ()
public IntPtr ToHfont ()
public function ToHfont () : IntPtr

Rückgabewert

Ein Windows-Handle für diesen Font.

Ausnahmen

Ausnahmetyp Bedingung

Win32Exception

Die Operation war nicht erfolgreich.

Hinweise

Wenn Sie diese Methode verwenden, müssen Sie den resultierenden Hfont mithilfe der GDIDeleteObject-Methode freigeben, um sicherzustellen, dass die Ressourcen freigegeben werden.

Beispiel

Im folgenden Codebeispiel wird ein Font erstellt und daraufhin ein Handle für diesen Font abgerufen. Das Beispiel ist für die Verwendung mit Windows Forms vorgesehen und erfordert PaintEventArgse, wobei es sich um einen Parameter des Paint-Ereignishandlers handelt.

' 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
//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 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.
/** @attribute System.Runtime.InteropServices.DllImport("GDI32.dll")
 */
public static native boolean 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);
} //ToHfont_Example

.NET Framework-Sicherheit

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0

Siehe auch

Referenz

Font-Klasse
Font-Member
System.Drawing-Namespace