123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- 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;
- namespace LYFZ.ComponentLibrary
- {
- public partial class frmCommonIconView : LYFZ.ComponentLibrary.BaseContentsFormMain
- {
- public frmCommonIconView()
- {
- InitializeComponent();
- this.Load += frmCommonIconView_Load;
- this.Shown += frmCommonIconView_Shown;
- this.listView1.ItemSelectionChanged += listView1_ItemSelectionChanged;
- this.btnSave.Click += btnSave_Click;
- }
- void btnSave_Click(object sender, EventArgs e)
- {
- this.DialogResult = System.Windows.Forms.DialogResult.OK;
- }
- void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
- {
- if (e.Item != null && e.IsSelected)
- {
- this.picICO.Image = this.listView1.LargeImageList.Images[e.Item.ImageIndex];
- this.SelectIconPath = e.Item.Tag.ToString();
- }
- }
- string _SelectIconPath = "";
- /// <summary>
- /// 当前选择图标路径
- /// </summary>
- public string SelectIconPath
- {
- get { return _SelectIconPath; }
- set { _SelectIconPath = value; }
- }
- //创建一个委托,是为访问DataGridVie控件服务的。
- public delegate void UpdateControl();
- /// <summary>
- /// 显示相片集合
- /// </summary>
- static ImageList ICOImgeList = new ImageList();
- /// <summary>
- /// 系统图标目录路径
- /// </summary>
- static string sysTempHeadImagePath = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(LYFZ.WinAPI.CustomPublicMethod.BasePath) + "Resources\\快捷工具图标\\";
- public static string GetDefaultIconPath()
- {
- return sysTempHeadImagePath + "other\\question.png";
- }
- void frmCommonIconView_Shown(object sender, EventArgs e)
- {
- if (ICOImge != null)
- {
- this.picICO.Image = ICOImge;
- }
-
- if (System.IO.Directory.Exists(sysTempHeadImagePath))
- {
- string[] sysTempHeadImageFiles = System.IO.Directory.GetFiles(sysTempHeadImagePath, "*.png", System.IO.SearchOption.AllDirectories);
- if (ICOImgeList.Images.Count <= 0)
- {
- ICOImgeList.Images.Clear();
- ICOImgeList.ColorDepth = ColorDepth.Depth32Bit;
- ICOImgeList.ImageSize = new Size(64, 64);
-
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
- {
- backgroundWorker.ReportProgress(0, "正在加载图标...");
- foreach (string imagePath in sysTempHeadImageFiles)
- {
- Image smallImage = GetNewBitmap(imagePath);
- ICOImgeList.Images.Add(imagePath, smallImage);
- }
- });
- }
- int count = 0;
- foreach (string imagePath in sysTempHeadImageFiles)
- {
- string PhotoName = "ICO_" + count.ToString().PadLeft(3, '0');
- ListViewItem lvi = new ListViewItem();
- lvi.Name = PhotoName;
- lvi.ImageIndex = 0;
- lvi.Text = PhotoName;
- lvi.Tag = imagePath;
- lvi.ToolTipText = lvi.Text;
- this.listView1.Items.Add(lvi);
- count++;
- }
-
-
- }
- this.listView1.LargeImageList = ICOImgeList;
- this.listView1.View = View.LargeIcon;
- this.listView1.Sorting = SortOrder.Ascending;
- this.listView1.Sort();
- RefreshShowPhotoImageList();
- }
- void frmCommonIconView_Load(object sender, EventArgs e)
- {
-
- }
- /// <summary>
- /// 刷新图片列表缩略图显示
- /// </summary>
- /// <param name=""></param>
- void RefreshShowPhotoImageList()
- {
- for (int i = 0; i < this.listView1.Items.Count; i++)
- {
- // if (this.listView1.Items[i].ImageIndex == 0)
- //{
- if (this.listView1.Items[i].Tag != null)
- {
- string lvpPhotoName = this.listView1.Items[i].Tag.ToString();
- if (this.listView1.LargeImageList.Images.ContainsKey(lvpPhotoName.ToLower()))
- {
- this.listView1.Items[i].ImageIndex = this.listView1.LargeImageList.Images.IndexOfKey(lvpPhotoName.ToLower());
- }
- if (!string.IsNullOrEmpty(this.SelectIconPath.Trim()))
- {
- if (this.listView1.LargeImageList.Images.ContainsKey(this.SelectIconPath.ToLower()))
- {
- this.picICO.Image = this.listView1.LargeImageList.Images[this.listView1.LargeImageList.Images.IndexOfKey(this.SelectIconPath.ToLower())];
- }
- }
- }
- // }
- }
- }
- /// <summary>
- /// 通过图片对像返回新图片但不占用文件
- /// </summary>
- /// <param name="_imgFilePath">image对象在返时被释放</param>
- /// <returns></returns>
- public static Bitmap GetNewBitmap(string _imgFilePath)
- {
- Image image = new Bitmap(_imgFilePath);
- try
- {
- return new Bitmap(image);
- }
- catch
- {
- return new Bitmap(1, 1);
- }
- finally
- {
- if (image != null)
- {
- image.Dispose();
- }
- }
- }
- System.Drawing.Image _ICOImge = null;
- /// <summary>
- /// 图标
- /// </summary>
- public System.Drawing.Image ICOImge
- {
- get { return _ICOImge; }
- set { _ICOImge = value; }
- }
- }
- }
|