Font.ToHfont Metoda

Definicja

Zwraca dojście do tego Font.

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

Zwraca

IntPtr

nativeint

Dojście systemu Windows do tego Font.

Wyjątki

Operacja nie powiodła się.

Przykłady

Poniższy przykład kodu tworzy obiekt , Font a następnie pobiera do tego Fontdojście. Przykład jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgseparametru , który jest parametrem Paint programu obsługi zdarzeń.

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

Uwagi

W przypadku korzystania z tej metody należy usunąć wynikowe Hfont użycie metody GDI DeleteObject , aby upewnić się, że zasoby zostaną zwolnione.

Dotyczy