Bitmap.FromHicon(IntPtr) 方法
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建从 Windows 句柄到图标的 Bitmap。
public:
static System::Drawing::Bitmap ^ FromHicon(IntPtr hicon);
C#
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 窗体,它需要 PaintEventArgse
,这是 Paint 事件处理程序的参数。 该代码执行以下操作:
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 );
}
C#
[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
产品 | 版本 |
---|---|
.NET | 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |