Font.ToHfont Yöntem

Tanım

Bu Fontöğesine bir tanıtıcı döndürür.

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

Döndürülenler

IntPtr

nativeint

Bunun Fontiçin bir Windows tanıtıcısı.

Özel durumlar

İşlem başarısız oldu.

Örnekler

Aşağıdaki kod örneği bir Font oluşturur ve ardından bunun Fontbir tanıtıcısını alır. Örnek, Windows Forms ile kullanılmak üzere tasarlanmıştır ve PaintEventArgseolay işleyicisinin Paint bir parametresi olan gerektirir.

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

Açıklamalar

Bu yöntemi kullanırken, kaynakların serbest bırakıldığından emin olmak için GDI DeleteObject yöntemini kullanarak elde Hfont edileni atmalısınız.

Şunlara uygulanır