C# 获取系统图标

1 代码

[csharp] view plain copy
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. using System.Runtime.InteropServices;  
  10.   
  11.   
  12. namespace TestControls  
  13. {  
  14.     public partial class Form2 : Form  
  15.     {  
  16.         public Form2()  
  17.         {  
  18.             InitializeComponent();  
  19.         }  
  20.   
  21.     
  22.         [DllImport("user32.dll", CharSet = CharSet.Auto)]  
  23.         private static extern bool MessageBeep(uint type);  
  24.   
  25.         [DllImport("Shell32.dll")]  
  26.         public extern static int ExtractIconEx(string libName, int iconIndex, IntPtr[] largeIcon, IntPtr[] smallIcon, int nIcons);  
  27.   
  28.         public static IntPtr[] largeIcon;  
  29.         public static IntPtr[] smallIcon;  
  30.   
  31.         private void Form1_Load(object sender, EventArgs e)  
  32.         {  
  33.             largeIcon = new IntPtr[250];  
  34.             smallIcon = new IntPtr[250];  
  35.   
  36.             ExtractIconEx("shell32.dll", 0, largeIcon, smallIcon, 250);  
  37.   
  38.             for (int i = 1; i < 200; ++i)  
  39.             {  
  40.                 Icon ic = Icon.FromHandle(largeIcon[i]);  
  41.                 ((PictureBox)this.Controls["pictureBox" + i.ToString()]).Image = ic.ToBitmap();  
  42.             }  
  43.         }  
  44.     }  
  45. }  

2 效果图


C# 获取系统图标