public ProjectPanel(IManager manager) { InitializeComponent(); m_manager = manager; m_mainWindow = (MainWindow)manager.MainWindow; m_manager.PropertyChange += new PropertyChangeEventHandler(Manager_PropertyChange); manager.ProjectOpened += new ProjectOpenedEventHandler(Manager_ProjectOpened); m_systemImageList = new SystemImageList(); m_systemImageList.SetImageList(projectView); m_italicFont = new Font(projectView.Font, FontStyle.Italic); m_boldFont = new Font(projectView.Font, FontStyle.Bold); UpdateTree(); foreach (Type docType in m_manager.GetPluginImplementations(typeof(Document))) { DocumentClassAttribute docAttr = DocumentClassAttribute.ForType(docType); if (docAttr != null) { ToolStripMenuItem item = new ToolStripMenuItem(); item.Text = "New " + docAttr.Name; item.Click += new EventHandler(AddNewDocument_Click); item.Tag = docType; addToolStripMenuItem.DropDownItems.Insert(0, item); } } }
public Bitmap GetBitmap(IconSize size, string fileName, bool isDirectory, bool forceLoad) { Bitmap retVal = null; using (var imgList = new SystemImageList(size)) retVal = imgList[fileName, isDirectory, forceLoad]; //sysImgListLock.AcquireReaderLock(1000); //try //{ // if (!sysImgList.IsImageListInited || size != sysImgList.CurrentImageListSize) // { // LockCookie lockCookie = sysImgListLock.UpgradeToWriterLock(lockWaitTime); // try // { // SystemImageList imgList = sysImgList[size]; // retVal = imgList[fileName, isDirectory, forceLoad]; // } // finally // { // sysImgListLock.DowngradeFromWriterLock(ref lockCookie); // } // } // else // { // retVal = sysImgList[size][fileName, isDirectory, forceLoad]; // } //} //finally { sysImgListLock.ReleaseReaderLock(); } return(retVal); }
public Bitmap GetBitmap(IconSize size, string fileName, bool isDirectory, bool forceLoad) { Bitmap retVal = null; sysImgListLock.AcquireReaderLock(1000); try { if (!sysImgList.IsImageListInited || size != sysImgList.CurrentImageListSize) { LockCookie lockCookie = sysImgListLock.UpgradeToWriterLock(Timeout.Infinite); try { SystemImageList imgList = sysImgList[size]; retVal = imgList[fileName, isDirectory, forceLoad]; } finally { sysImgListLock.DowngradeFromWriterLock(ref lockCookie); } } else { retVal = sysImgList[size][fileName, isDirectory, forceLoad]; } } finally { sysImgListLock.ReleaseReaderLock(); } return(retVal); }
public FileSystemTreeBrowser() { InitializeComponent(); // Set the TreeView image list to the system image list. SystemImageList.SetTVImageList(treeWnd.Handle); LoadRootNodes(); treeWnd.AfterSelect += new TreeViewEventHandler(treeWnd_AfterSelect); }
private void GetInfo(FileInfo fi) { Name = fi.Name; Size = fi.Length; Hidden = (FileAttributes.Hidden & fi.Attributes) > 0 ? true : false; CreatedTime = fi.CreationTimeUtc; LastAccessTime = fi.LastAccessTimeUtc; LastModifiedTime = fi.LastWriteTimeUtc; if (Extension.ToLower() == ".exe" || Extension.ToLower() == ".ttf" || Extension.ToLower() == ".ico") { int index = CommVar.sil_l.IconIndex(fi.FullName, false); SystemImageList.SHGetFileInfo( Extension, FILE_ATTRIBUTE_NORMAL, ref shfi, shfiSize, (uint)dwFlags); if (shfi.iIcon == index) { return; } else { thisIconIndex = index; } Path = fi.FullName; CommVar.mi.Clear(); SingleIcon singleIcon = CommVar.mi.Add("Untitled"); if (CommVar.IsVista) { singleIcon.Add(CommVar.sil_v.Icon(IconIndex)); } singleIcon.Add(CommVar.sil_x.Icon(IconIndex)); singleIcon.Add(CommVar.sil_l.Icon(IconIndex)); singleIcon.Add(CommVar.sil_s.Icon(IconIndex)); CommVar.mi.SelectedIndex = 0; CommVar.mi.Save(CommVar.TempFolder + @"\temp.ico", MultiIconFormat.ICO); FileStream fs = new FileStream(CommVar.TempFolder + @"\temp.ico", FileMode.Open, FileAccess.Read, FileShare.None); byte[] fbs = new byte[fs.Length]; fs.Read(fbs, 0, (int)fs.Length); fs.Close(); fs.Dispose(); IconData = fbs; File.Delete(CommVar.TempFolder + @"\temp.ico"); Path = ""; } }
/// <summary> /// Extract the icon for the file type (Extension) /// </summary> protected virtual void SetIcon(TreeViewFolderBrowser treeView, TreeNodePath node) { // create on demand if (_systemImageList == null) { // Shell32 ImageList _systemImageList = new SystemImageList(SystemImageListSize.SmallIcons); SystemImageListHelper.SetTreeViewImageList(treeView, _systemImageList, false); } node.ImageIndex = _systemImageList.IconIndex(node.Path, true); node.SelectedImageIndex = node.ImageIndex; }
/// <summary> /// Associates a SysImageList with a TreeView control /// </summary> /// <param name="treeView">TreeView control to associated ImageList with</param> /// <param name="sysImageList">System Image List to associate</param> /// <param name="forStateImages">Whether to add ImageList as StateImageList</param> public static void SetTreeViewImageList( System.Windows.Forms.TreeView treeView, SystemImageList sysImageList, bool forStateImages ) { System.IntPtr wParam = (System.IntPtr)TVSIL_NORMAL; if (forStateImages) { wParam = (System.IntPtr)TVSIL_STATE; } SendMessage( treeView.Handle, TVM_SETIMAGELIST, wParam, sysImageList.Handle); }
/// <summary> /// Associates a SysImageList with a ListView control /// </summary> /// <param name="listView">ListView control to associate ImageList with</param> /// <param name="sysImageList">System Image List to associate</param> /// <param name="forStateImages">Whether to add ImageList as StateImageList</param> public static void SetListViewImageList( System.Windows.Forms.ListView listView, SystemImageList sysImageList, bool forStateImages ) { System.IntPtr wParam = (System.IntPtr)LVSIL_NORMAL; if (sysImageList.ImageListSize == SystemImageListSize.SmallIcons) { wParam = (System.IntPtr)LVSIL_SMALL; } if (forStateImages) { wParam = (System.IntPtr)LVSIL_STATE; } SendMessage( listView.Handle, LVM_SETIMAGELIST, wParam, sysImageList.Handle); }
/// <summary> /// Associates a SysImageList with a TreeView control /// </summary> /// <param name="treeView">TreeView control to associated ImageList with</param> /// <param name="sysImageList">System Image List to associate</param> /// <param name="forStateImages">Whether to add ImageList as StateImageList</param> public static void SetTreeViewImageList( System.Windows.Forms.TreeView treeView, SystemImageList sysImageList, bool forStateImages ) { System.IntPtr wParam = (System.IntPtr) TVSIL_NORMAL; if (forStateImages) { wParam = (System.IntPtr) TVSIL_STATE; } SendMessage( treeView.Handle, TVM_SETIMAGELIST, wParam, sysImageList.Handle); }
/// <summary> /// Associates a SysImageList with a ListView control /// </summary> /// <param name="listView">ListView control to associate ImageList with</param> /// <param name="sysImageList">System Image List to associate</param> /// <param name="forStateImages">Whether to add ImageList as StateImageList</param> public static void SetListViewImageList( System.Windows.Forms.ListView listView, SystemImageList sysImageList, bool forStateImages ) { System.IntPtr wParam = (System.IntPtr) LVSIL_NORMAL; if (sysImageList.ImageListSize == SystemImageListSize.SmallIcons) { wParam = (System.IntPtr) LVSIL_SMALL; } if (forStateImages) { wParam = (System.IntPtr) LVSIL_STATE; } SendMessage( listView.Handle, LVM_SETIMAGELIST, wParam, sysImageList.Handle); }
public ShellListViewPane() { InitializeComponent(); flowLayoutPanel1.HorizontalScroll.Visible = false; flowLayoutPanel1.VerticalScroll.Visible = false; shellListView1.Enter += delegate(object _sender, EventArgs _e) { //Update all the Shell Components in the main form to react to this Pane. OnFocusChange(this, null); panel1.BorderStyle = BorderStyle.FixedSingle; }; shellListView1.Leave += delegate(object _sender, EventArgs _e) { panel1.BorderStyle = BorderStyle.None; }; #region Configuration Menu //Reset all the controls to default shellControlConnector1.ShowParentfolderItem = shellListView1.ShowParentFolder; showParentFolderToolStripMenuItem.Checked = shellListView1.ShowParentFolder; showHiddenObjectsToolStripMenuItem.Checked = shellListView1.ShowHidden; showOverlayIconsToolStripMenuItem.Checked = shellListView1.ShowOverlayIcons; useSystemFontToolStripMenuItem.Checked = shellListView1.UseSystemFont; fileSystemOnlyToolStripMenuItem.Checked = shellListView1.FileSystemOnly; #endregion #region Checkboxes scanRecursivelyToolStripMenuItem.Checked = shellControlConnector1.SelectionList.CalculateSelectedFiles; toggleCheckboxesToolStripMenuItem.Checked = shellListView1.CheckBoxes; shellControlConnector1.SelectionList.SelectionChanged += delegate(object _sender, EventArgs _e) { CheckboxListIsCalculatingSize = true; //Keep track if we have finished calculating the size }; shellControlConnector1.SelectionList.CompletedSizeCalculation += delegate(object _sender, EventArgs _e) { CheckboxListIsCalculatingSize = false; }; #endregion #region Drives ShellBrowser browser = new ShellBrowser(ShellFolder.Drives); //Initialize a new Browser with the Root point at "This PC" while (browser.Next()) //Browse through all Items listed at Root Point { if (PathCollection.IsDrive(browser.FullPath) || browser.HasAttributes(SFGAOF.SFGAO_REMOVABLE)) { var path = browser.FullPath; //Read the DisplayPath from the ShellBrowser instance //Create a button with the drive icon next to the text. Button driveBtn = new Button { ImageAlign = ContentAlignment.MiddleRight, TextImageRelation = TextImageRelation.ImageBeforeText, TextAlign = ContentAlignment.MiddleCenter }; int index = SystemImageList.GetIndexFromItemIdList(ItemIdList.Parse(path), false); driveBtn.Image = new SystemImageListHelper().GetIconAsBitmap(index); driveBtn.Text = path; driveBtn.Width = 0; driveBtn.AutoSize = true; driveBtn.Click += delegate(object a, EventArgs b) { //When the button is clicked, go to the path by setting the FolderIdList Property. shellListView1.FolderChanged(ItemIdList.Parse(path)); }; flowLayoutPanel1.Controls.Add(driveBtn); } } #endregion }