private void mIconButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog lOpenFileDialog = new OpenFileDialog();

            lOpenFileDialog.Multiselect = false;
            lOpenFileDialog.Filter      = "Icon File(*.ico;*.icl;*.exe;*.dll)|*.ico;*.icl;*.exe;*.dll";
            lOpenFileDialog.ShowDialog();
            if (!string.IsNullOrEmpty(lOpenFileDialog.FileName))
            {
                this.mIconPath         = lOpenFileDialog.FileName;
                this.mIconButton.Image = SystemIcon.GetFileIcon(lOpenFileDialog.FileName, false).ToBitmap();
            }
        }
Exemple #2
0
        void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            TreeNode newSelected = e.Node;
            var      dirPath     = newSelected.Tag.ToString();

            if (string.IsNullOrEmpty(dirPath))
            {
                return;
            }
            DirectoryInfo dir = new DirectoryInfo(dirPath);

            if (!dir.Exists)
            {
                return;
            }
            try
            {
                LoadTreeDir(newSelected, dir);
                loadListDir(dir);

                foreach (FileInfo file in dir.GetFiles())
                {
                    var key = file.Extension.ToLower();
                    if (key == ".exe")
                    {
                        key = file.Name;
                    }
                    if (!imageList1.Images.ContainsKey(key))
                    {
                        this.imageList1.Images.Add(key, SystemIcon.GetFileIcon(file.FullName, true));
                    }
                    var item = new ListViewItem(file.Name, key);
                    item.Tag = file.FullName;
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "File"));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, file.LastAccessTime.ToShortDateString()));
                    listView1.Items.Add(item);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
        }