/// <summary> /// 将文件添加到ListView中 /// </summary> private void refreshShortcut(string groupName, ListView listViewFiles) { this.largeIconImageList = new ImageList() { ImageSize = new Size(32, 32), ColorDepth = ColorDepth.Depth32Bit }; this.smallIconImageList = new ImageList() { ImageSize = new Size(16, 16), ColorDepth = ColorDepth.Depth32Bit }; listViewFiles.LargeImageList = largeIconImageList; listViewFiles.SmallImageList = smallIconImageList; IList <BoxFile> boxFiles = BoxFileData.getShortcuts(groupName); ListViewItem listViewItem; BoxFile boxFileItem; listViewFiles.Items.Clear(); if (boxFiles != null && boxFiles.Count > 0) { for (int i = 0; i < boxFiles.Count; i++) { boxFileItem = boxFiles[i]; this.largeIconImageList.Images.Add(boxFileItem.LargeIcon); this.smallIconImageList.Images.Add(boxFileItem.SmallIcon); listViewItem = new ListViewItem(); listViewItem.Text = boxFileItem.Name; listViewItem.Tag = boxFileItem; listViewItem.ImageIndex = i; listViewItem.SubItems.AddRange(new string[] { boxFileItem.Path }); listViewFiles.Items.Add(listViewItem); } } }
/// <summary> /// 将文件添加到托盘右键菜单中 /// </summary> private void FlushTrayChildMenuInGroup(ToolStripMenuItem toolStripSubMenu, string groupName) { this.smallIconImageList = new ImageList() { ImageSize = new Size(16, 16), ColorDepth = ColorDepth.Depth32Bit }; IList <BoxFile> boxFiles = BoxFileData.getShortcuts(groupName); toolStripSubMenu.DropDownItems.Clear(); if (boxFiles != null && boxFiles.Count > 0) { ToolStripMenuItem toolStripMenuItem; BoxFile boxFileItem; for (int i = 0; i < boxFiles.Count; i++) { boxFileItem = boxFiles[i]; this.smallIconImageList.Images.Add(boxFileItem.SmallIcon); toolStripMenuItem = new ToolStripMenuItem(); toolStripMenuItem.Text = boxFileItem.Name; toolStripMenuItem.ToolTipText = boxFileItem.Name; toolStripMenuItem.Tag = boxFileItem; toolStripMenuItem.Image = this.smallIconImageList.Images[i]; toolStripMenuItem.Click += new EventHandler(toolStripSubMenu_Click); toolStripSubMenu.DropDownItems.Add(toolStripMenuItem); } boxFileItem = null; boxFiles = null; toolStripMenuItem = null; } }