アイコンを識別する Windows ハンドルから Bitmap を作成します。
Public Shared Function FromHicon( _
ByVal hicon As IntPtr _) As Bitmap
[C#]
public static Bitmap FromHicon(IntPtrhicon);
[C++]
public: static Bitmap* FromHicon(IntPtrhicon);
[JScript]
public static function FromHicon(
hicon : IntPtr) : Bitmap;
パラメータ
- hicon
アイコンを識別するハンドル。
戻り値
このメソッドが作成する Bitmap オブジェクト。
使用例
[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードは次のアクションを実行します。
Private Shared Function <System.Runtime.InteropServices.DllImportAttribute("user32.dll")> LoadImage(Hinstance As Integer, name As String, type As Integer, width As Integer, height As Integer, load As Integer) As IntPtr
Public Sub HICON_Example(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
[C#]
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
private static extern IntPtr LoadImage(
int Hinstance,
string name,
int type,
int width,
int height,
int load);
public 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);
}
[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ