Bitmap.FromHicon(IntPtr) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從圖示的 Windows 控制代碼建立 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 使用而設計,而且需要 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 );
}
[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
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應