Icon.FromHandle メソッド
アセンブリ: System.Drawing (system.drawing.dll 内)

Dim handle As IntPtr Dim returnValue As Icon returnValue = Icon.FromHandle(handle)
戻り値
このメソッドが作成する Icon。


次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
<System.Runtime.InteropServices.DllImportAttribute("user32.dll")> _ Private Shared Function DestroyIcon(ByVal handle _ As IntPtr) As Boolean End Function Private Sub GetHicon_Example(ByVal e As PaintEventArgs) ' Create a Bitmap object from an image file. Dim myBitmap As New Bitmap("c:\FakePhoto.jpg") ' Draw myBitmap to the screen. e.Graphics.DrawImage(myBitmap, 0, 0) ' Get an Hicon for myBitmap. Dim HIcon As IntPtr = myBitmap.GetHicon() ' Create a new icon from the handle. Dim newIcon as Icon = System.Drawing.Icon.FromHandle(HIcon) ' Set the form Icon attribute to the new icon. Me.Icon = newIcon ' Destroy the icon, since the form creates its ' own copy of the icon. DestroyIcon(newIcon.Handle) End Sub
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet=CharSet.Auto)] extern static bool DestroyIcon(IntPtr handle); private void GetHicon_Example(PaintEventArgs e) { // Create a Bitmap object from an image file. Bitmap myBitmap = new Bitmap(@"c:\FakePhoto.jpg"); // Draw myBitmap to the screen. e.Graphics.DrawImage(myBitmap, 0, 0); // Get an Hicon for myBitmap. IntPtr Hicon = myBitmap.GetHicon(); // Create a new icon from the handle. Icon newIcon = Icon.FromHandle(Hicon); // Set the form Icon attribute to the new icon. this.Icon = newIcon; // Destroy the Icon, since the form creates // its own copy of the icon. DestroyIcon(newIcon.Handle); }
private: [System::Runtime::InteropServices::DllImportAttribute("user32.dll",CharSet=CharSet::Auto)] static bool DestroyIcon( IntPtr handle ); public: [SecurityPermission(SecurityAction::Demand, Flags=SecurityPermissionFlag::UnmanagedCode)] void GetHicon_Example( PaintEventArgs^ e ) { // Create a Bitmap object from an image file. Bitmap^ myBitmap = gcnew Bitmap( "c:\\FakePhoto.jpg" ); // Draw myBitmap to the screen. e->Graphics->DrawImage( myBitmap, 0, 0 ); // Get an Hicon for myBitmap. IntPtr Hicon = myBitmap->GetHicon(); // Create a new icon from the handle. System::Drawing::Icon^ newIcon = ::Icon::FromHandle( Hicon ); // Set the form Icon attribute to the new icon. this->Icon = newIcon; // Destroy the Icon, since the form creates // its own copy of the icon. DestroyIcon( newIcon->Handle ); }

- SecurityPermission (アンマネージ コードへのアクセス許可)。UnmanagedCode (関連する列挙体)

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Icon.FromHandle メソッドのページへのリンク