Bitmap.FromHicon(IntPtr) Bitmap.FromHicon(IntPtr) Bitmap.FromHicon(IntPtr) Bitmap.FromHicon(IntPtr) Method

定義

アイコンへの Windows ハンドルから Bitmap を作成します。Creates a Bitmap from a Windows handle to an icon.

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

アイコンにへのハンドル。A handle to an icon.

戻り値

このメソッドが作成する BitmapThe Bitmap that this method creates.

次のコード例は、Windows フォームで使用するように設計されています。また、Paint イベントハンドラーのパラメーターである @no__t 0 の @ no__t-1 が必要です。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:

  • 既存のアイコンイメージへのハンドルを取得します。Gets the handle to an existing icon image.

  • ハンドルから Bitmap を作成します。Creates a Bitmap from the handle.

  • 画面に @no__t 0 を描画します。Draws the Bitmap to the screen.

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

セキュリティ

SecurityPermission
アンマネージコードを呼び出すための。for calling into unmanaged code. 関連する列挙値: UnmanagedCodeRelated enumeration: UnmanagedCode

適用対象