Icon.FromHandle メソッドとは? わかりやすく解説

Icon.FromHandle メソッド

アイコン (HICON) を識別する指定Windows ハンドルから GDI+ Icon作成します

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Shared Function FromHandle
 ( _
    handle As IntPtr _
) As Icon
public static Icon FromHandle (
    IntPtr handle
)
public:
static Icon^ FromHandle (
    IntPtr handle
)
public static Icon FromHandle (
    IntPtr handle
)
public static function FromHandle
 (
    handle : IntPtr
) : Icon

パラメータ

handle

アイコン識別する Windows ハンドル

戻り値
このメソッド作成する 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 );
   }
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

Icon.FromHandle メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Icon.FromHandle メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS