Font.ToHfont Methode

Definitie

Hiermee wordt een ingang geretourneerd.Font

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

Retouren

IntPtr

nativeint

Een Windows aan deze Font.

Uitzonderingen

De bewerking is mislukt.

Voorbeelden

In het volgende codevoorbeeld wordt een Font en vervolgens een ingang naar dat Fontbestand gemaakt. Het voorbeeld is ontworpen voor gebruik met Windows Forms en vereist PaintEventArgse, een parameter van de Paint gebeurtenis-handler.

   //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

Opmerkingen

Wanneer u deze methode gebruikt, moet u de resulterende Hfont methode verwijderen met behulp van de GDI-methode DeleteObject om ervoor te zorgen dat de resources worden vrijgegeven.

Van toepassing op