Font.ToHfont 메서드

정의

Font의 핸들을 반환합니다.

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

반환

IntPtr

nativeint

Font에 대한 창 핸들입니다.

예외

작업에 실패한 경우

예제

다음 코드 예제에서는 를 만든 Font 다음 해당 Font에 대한 핸들을 가져옵니다. 이 예제는 Windows Forms 사용하도록 설계되었으며 이벤트 처리기의 매개 변수인 가 필요합니다PaintEventArgse.Paint

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

설명

이 메서드를 사용하는 경우 GDI DeleteObject 메서드를 Hfont 사용하여 결과를 삭제하여 리소스가 해제되도록 해야 합니다.

적용 대상