Font.FromHfont(IntPtr) 메서드

정의

지정된 창 핸들에서 Font를 만듭니다.Creates a Font from the specified Windows handle.

public:
 static System::Drawing::Font ^ FromHfont(IntPtr hfont);
public static System.Drawing.Font FromHfont (IntPtr hfont);
static member FromHfont : nativeint -> System.Drawing.Font
Public Shared Function FromHfont (hfont As IntPtr) As Font

매개 변수

hfont
IntPtr

GDIGDI 글꼴에 대한 창 핸들입니다.A Windows handle to a GDIGDI font.

반환

이 메서드가 만드는 Font입니다.The Font this method creates.

예외

hfont가 트루타입 글꼴이 아닌 개체를 가리키는 경우hfont points to an object that is not a TrueType font.

예제

다음 코드 예제는 Windows Forms에서 사용 하도록 설계 되었으며 필요 PaintEventArgs e의 매개 변수는 Paint 이벤트 처리기입니다.The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 이 코드에서는 다음 작업을 수행합니다.The code performs the following actions:

  • 에 대 한 핸들을 가져옵니다는 GDIGDI 글꼴입니다.Gets a handle to a GDIGDI font.

  • 만듭니다는 Font 해당 핸들에서입니다.Creates a Font from that handle.

  • 새 화면에 텍스트를 그립니다 Font합니다.Draws text to the screen, using the new Font.

private:
   [System::Runtime::InteropServices::DllImportAttribute("gdi32.dll")]
   static IntPtr GetStockObject( int fnObject );

public:
   void FromHfont_Example( PaintEventArgs^ e )
   {
      // Get a handle for a GDI font.
      IntPtr hFont = GetStockObject( 17 );

      // Create a Font object from hFont.
      System::Drawing::Font^ hfontFont = System::Drawing::Font::FromHfont( hFont );

      // Use hfontFont to draw text to the screen.
      e->Graphics->DrawString( "This font is from a GDI HFONT", hfontFont, Brushes::Black, 0, 0 );
   }
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern IntPtr GetStockObject(int fnObject);
public void FromHfont_Example(PaintEventArgs e)
{
             
    // Get a handle for a GDI font.
    IntPtr hFont = GetStockObject(0);
             
    // Create a Font object from hFont.
    Font hfontFont = Font.FromHfont(hFont);
             
    // Use hfontFont to draw text to the screen.
    e.Graphics.DrawString(
        "This font is from a GDI HFONT", hfontFont,Brushes.Black, 
        0, 0);
       
        
        
        
}
<System.Runtime.InteropServices.DllImportAttribute("GDI32.DLL")> _
Private Shared Function GetStockObject(ByVal fnObject As Integer) As IntPtr
End Function
Public Sub FromHfont_Example(ByVal e As PaintEventArgs)

    ' Get a handle for a GDI font.
    Dim hFont As IntPtr = GetStockObject(17)

    ' Create a Font object from hFont.
    Dim hfontFont As Font = Font.FromHfont(hFont)

    ' Use hfontFont to draw text to the screen.
    e.Graphics.DrawString("This font is from a GDI HFONT", hfontFont, _
    Brushes.Black, 0, 0)
End Sub

보안

SecurityPermission
비관리 코드에 액세스 합니다.for access to unmanaged code. 연관 된 열거: UnmanagedCodeRelated enumeration: UnmanagedCode

적용 대상