码迷,mamicode.com
首页 > Windows程序 > 详细

C# 获取系统图标

时间:2016-07-15 21:11:40      阅读:439      评论:0      收藏:0      [点我收藏+]

标签:


1 代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;


namespace TestControls
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

  
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern bool MessageBeep(uint type);

        [DllImport("Shell32.dll")]
        public extern static int ExtractIconEx(string libName, int iconIndex, IntPtr[] largeIcon, IntPtr[] smallIcon, int nIcons);

        public static IntPtr[] largeIcon;
        public static IntPtr[] smallIcon;

        private void Form1_Load(object sender, EventArgs e)
        {
            largeIcon = new IntPtr[250];
            smallIcon = new IntPtr[250];

            ExtractIconEx("shell32.dll", 0, largeIcon, smallIcon, 250);

            for (int i = 1; i < 200; ++i)
            {
                Icon ic = Icon.FromHandle(largeIcon[i]);
                ((PictureBox)this.Controls["pictureBox" + i.ToString()]).Image = ic.ToBitmap();
            }
        }
    }
}

2 效果图


技术分享






C# 获取系统图标

标签:

原文地址:http://blog.csdn.net/taoerit/article/details/51917528

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!