Bitmap.FromHicon(IntPtr) 메서드

정의

창 핸들에서 아이콘까지 Bitmap을 만듭니다.

public:
 static System::Drawing::Bitmap ^ FromHicon(IntPtr hicon);
public static System.Drawing.Bitmap FromHicon (IntPtr hicon);
static member FromHicon : nativeint -> System.Drawing.Bitmap
Public Shared Function FromHicon (hicon As IntPtr) As Bitmap

매개 변수

hicon
IntPtr

nativeint

아이콘에 대한 핸들입니다.

반환

이 메서드가 만드는 Bitmap입니다.

예제

다음 코드 예제는 Windows Forms 사용하도록 설계되었으며 이벤트 처리기의 Paint 매개 변수인 가 필요합니다.PaintEventArgse 코드는 다음 작업을 수행합니다.

  • 기존 아이콘 이미지에 대한 핸들을 가져옵니다.

  • Bitmap 핸들에서 을 만듭니다.

  • Bitmap 를 화면에 그립니다.

private:
    [System::Runtime::InteropServices::DllImportAttribute("user32.dll", CharSet = CharSet::Unicode)]
   static IntPtr LoadImage( int Hinstance, String^ name, int type, int width, int height, int load );

private:
   void Hicon_Example( PaintEventArgs^ e )
   {
      
      // Get a handle to an icon.
      IntPtr Hicon = LoadImage( 0, "smile.ico", 1, 0, 0, 16 );
      
      // Create a Bitmap object from the icon handle.
      Bitmap^ iconBitmap = Bitmap::FromHicon( Hicon );
      
      // Draw the Bitmap object to the screen.
      e->Graphics->DrawImage( iconBitmap, 0, 0 );
   }
[System.Runtime.InteropServices.DllImportAttribute("user32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr LoadImage(int Hinstance,
    string name, int type, int width, int height, int load);

private void Hicon_Example(PaintEventArgs e)
{

    // Get a handle to an icon.
    IntPtr Hicon = LoadImage(0, "smile.ico", 1, 0, 0, 16);

    // Create a Bitmap object from the icon handle.
    Bitmap iconBitmap = Bitmap.FromHicon(Hicon);

    // Draw the Bitmap object to the screen.
    e.Graphics.DrawImage(iconBitmap, 0, 0);
}
<System.Runtime.InteropServices.DllImportAttribute("user32.dll", CharSet:=CharSet.Unicode)> _
Private Shared Function LoadImage(ByVal Hinstance As Integer, ByVal name As String, ByVal type As Integer, ByVal width As Integer, ByVal height As Integer, ByVal load As Integer) As IntPtr
End Function

Private Sub HICON_Example(ByVal e As PaintEventArgs)

    ' Get a handle to an icon.
    Dim Hicon As IntPtr = LoadImage(0, "smile.ico", 1, 0, 0, 16)

    ' Create a Bitmap object from the icon handle.
    Dim iconBitmap As Bitmap = Bitmap.FromHicon(Hicon)

    ' Draw the Bitmap object to the screen.
    e.Graphics.DrawImage(iconBitmap, 0, 0)
End Sub

적용 대상