📄 geticon.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime .InteropServices ;
namespace XP界面优化精灵
{
/// <summary>
/// GetIcon 的摘要说明。
/// </summary>
public class GetIcon : System.Windows.Forms.Form
{
[DllImport("shell32.dll", EntryPoint="ExtractIcon")] public static extern int ExtractIcon ( int hInst, string lpszExeFileName, int nIconIndex );
private string fname=@"c:\windows\system32\shell32.dll";
private string fullpath=@"c:\windows\system32\shell32.dll,0" ;
private int index=0;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox tb_path;
private System.Windows.Forms.Button bn_selectPath;
private System.Windows.Forms.Button bn_yes;
private System.Windows.Forms.Button bn_cancel;
private System.Windows.Forms.ImageList imageList;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.ListView Iconlist;
private System.ComponentModel.IContainer components;
public GetIcon()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.label1 = new System.Windows.Forms.Label();
this.tb_path = new System.Windows.Forms.TextBox();
this.bn_selectPath = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.bn_yes = new System.Windows.Forms.Button();
this.bn_cancel = new System.Windows.Forms.Button();
this.imageList = new System.Windows.Forms.ImageList(this.components);
this.listBox1 = new System.Windows.Forms.ListBox();
this.Iconlist = new System.Windows.Forms.ListView();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(14, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(150, 23);
this.label1.TabIndex = 0;
this.label1.Text = "在这个文件中查找图标:";
//
// tb_path
//
this.tb_path.Location = new System.Drawing.Point(14, 24);
this.tb_path.Name = "tb_path";
this.tb_path.Size = new System.Drawing.Size(334, 21);
this.tb_path.TabIndex = 1;
this.tb_path.Text = "";
//
// bn_selectPath
//
this.bn_selectPath.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.bn_selectPath.Location = new System.Drawing.Point(360, 24);
this.bn_selectPath.Name = "bn_selectPath";
this.bn_selectPath.TabIndex = 2;
this.bn_selectPath.Text = "浏览(&B)...";
this.bn_selectPath.Click += new System.EventHandler(this.bn_selectPath_Click);
//
// label2
//
this.label2.Location = new System.Drawing.Point(14, 50);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(156, 23);
this.label2.TabIndex = 3;
this.label2.Text = "从以下列表选择一个图标:";
//
// bn_yes
//
this.bn_yes.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.bn_yes.Location = new System.Drawing.Point(274, 288);
this.bn_yes.Name = "bn_yes";
this.bn_yes.TabIndex = 5;
this.bn_yes.Text = "确定";
this.bn_yes.Click += new System.EventHandler(this.bn_yes_Click);
//
// bn_cancel
//
this.bn_cancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.bn_cancel.Location = new System.Drawing.Point(360, 288);
this.bn_cancel.Name = "bn_cancel";
this.bn_cancel.TabIndex = 6;
this.bn_cancel.Text = "取消";
this.bn_cancel.Click += new System.EventHandler(this.bn_cancel_Click);
//
// imageList
//
this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
this.imageList.ImageSize = new System.Drawing.Size(32, 32);
this.imageList.TransparentColor = System.Drawing.Color.Black;
//
// listBox1
//
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(8, 76);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(270, 208);
this.listBox1.TabIndex = 0;
//
// Iconlist
//
this.Iconlist.AutoArrange = false;
this.Iconlist.FullRowSelect = true;
this.Iconlist.LargeImageList = this.imageList;
this.Iconlist.Location = new System.Drawing.Point(14, 68);
this.Iconlist.Name = "Iconlist";
this.Iconlist.Size = new System.Drawing.Size(422, 206);
this.Iconlist.SmallImageList = this.imageList;
this.Iconlist.StateImageList = this.imageList;
this.Iconlist.TabIndex = 7;
//
// GetIcon
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(448, 318);
this.Controls.Add(this.Iconlist);
this.Controls.Add(this.bn_cancel);
this.Controls.Add(this.bn_yes);
this.Controls.Add(this.label2);
this.Controls.Add(this.bn_selectPath);
this.Controls.Add(this.tb_path);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.HelpButton = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "GetIcon";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "更改图标";
this.Closing += new System.ComponentModel.CancelEventHandler(this.GetIcon_Closing);
this.Load += new System.EventHandler(this.GetIcon_Load);
this.ResumeLayout(false);
}
#endregion
private void bn_selectPath_Click(object sender, System.EventArgs e)
{
OpenFileDialog ofd =new OpenFileDialog ();
ofd.Filter="*.dll|*.dll|应用程序|*.exe|图标文件|*.ico|所有文件|*.*";
if(ofd.ShowDialog ()==DialogResult.OK )
{
this.tb_path .Text =ofd.FileName;
this.fname =ofd.FileName;
geticonlist();
}
}
private void bn_yes_Click(object sender, System.EventArgs e)
{
this.fullpath =this.fname +","+this.Iconlist.SelectedItems [0].Index;
this.Hide();
}
private void geticonlist()
{
this.Iconlist.Clear ();
this.imageList.Images.Clear ();
int total=ExtractIcon(1,fname,-1);
if(total<=0)
{
MessageBox.Show ("该文件没有图标资源.",action.Caption );
this.tb_path.Text =@"c:\windows\system32\shell32.dll";
fname=@"c:\windows\system32\shell32.dll";
geticonlist();
}
for(int i=0; i<total-1;i++)
{
Icon ico=Extract.GetIcon (fname,i);
this.imageList.Images.Add (ico);
this.Iconlist.Items.Add ("",i);
}
this.Iconlist.Items[index].Selected =true;
}
private void GetIcon_Load(object sender, System.EventArgs e)
{
this.TopMost =action.isTopMost ;
this.tb_path .Text =this.fname;
geticonlist();
}
public void setIconpath(string fname,int index)
{
this.fname =fname;
this.index =index;
}
public string geticonpath()
{
return this.fullpath;
}
private void bn_cancel_Click(object sender, System.EventArgs e)
{
this.fullpath="";
this.Hide ();
}
private void GetIcon_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel =true;
this.Hide ();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -