示例#1
0
        ToolStripMenuItemEx fileInfo(FileInfo file, int iLength)
        {
            ToolStripMenuItemEx iItem = new ToolStripMenuItemEx();
            ShellExtensions.SHFILEINFO shinfo = new ShellExtensions.SHFILEINFO();
            IntPtr hImgSmall = ShellExtensions.Win32.SHGetFileInfo(file.FullName, 0, ref shinfo,
               (uint)Marshal.SizeOf(shinfo),
                ShellExtensions.Win32.SHGFI_ICON |
                ShellExtensions.Win32.SHGFI_SMALLICON);
            System.Drawing.Icon shellIcon =
                System.Drawing.Icon.FromHandle(shinfo.hIcon);
            Image iImage = shellIcon.ToBitmap();
            ShellExtensions.Win32.DestroyIcon(shinfo.hIcon);
            iItem = new ToolStripMenuItemEx(file.Name, iImage);
            iItem.DoubleClick += new EventHandler(iItem_DoubleClick);
            iItem.MouseDown += new MouseEventHandler(iItem_Click);
            iItem.Path = file.FullName;
            IntPtr hFileInfo = ShellExtensions.Win32.SHGetFileInfo(file.FullName, 0, ref shinfo,
               (uint)Marshal.SizeOf(shinfo),
                ShellExtensions.Win32.SHGFI_TYPENAME);
            string[] sCultureText;
            if (System.Threading.Thread.CurrentThread.CurrentUICulture.ToString() == "de-DE")
                sCultureText = de;
            else
                sCultureText = en;

            iItem.ToolTipText = sCultureText[0] + shinfo.szTypeName + "\n";
            iItem.ToolTipText += sCultureText[1] + CalcSize(file.Length) + "\n";
            iItem.ToolTipText += sCultureText[2] + file.LastWriteTime + "\n";
            iItem.ToolTipText += sCultureText[3] + file.CreationTime + "\n";
            return iItem;
        }
示例#2
0
        void iItem_DropDownOpening(object sender, EventArgs e)
        {
            ToolStripMenuItemEx iParentItem = (ToolStripMenuItemEx)sender;
            string DirTemp = iParentItem.Path;
            DirectoryInfo nodeDirInfo = new DirectoryInfo(DirTemp);
            int i = 0;
            if (nodeDirInfo.Exists)
            {

                rootDir = DirTemp;
                iParentItem.DropDownItems.Clear();

                DirectoryInfo[] dir = null;
                try
                {
                    dir = nodeDirInfo.GetDirectories();
                }
                catch (UnauthorizedAccessException)
                {
                     ; ;
                }
                ToolStripMenuItemEx[] iItem;

                if (dir != null)
                {
                    iItem = new ToolStripMenuItemEx[dir.Length];
                    i = 0;
                    foreach (DirectoryInfo dDir in dir)
                    {
                        iItem[i] = new ToolStripMenuItemEx(dDir.Name, imageList.Images[0]);
                        iItem[i].Path = dDir.FullName;
                        iItem[i].DropDownItems.Add("...");
                        iItem[i].DropDown.Closing += new ToolStripDropDownClosingEventHandler(DropDown_Closing);
                        iItem[i].DropDownOpening += new EventHandler(iItem_DropDownOpening);
                        i++;
                    }
                    iParentItem.DropDownItems.AddRange(iItem);
                    iParentItem.DropDown.DoubleClick += new EventHandler(DropDown_DoubleClick);
                    iParentItem.DropDown.MouseClick += new MouseEventHandler(DropDown_MouseClick);
                }
                FileInfo[] fFile = null;
                try
                {
                    fFile = nodeDirInfo.GetFiles();
                }
                catch (UnauthorizedAccessException)
                {
                     ; ;
                }
                i = 0;
                if (fFile != null)
                {
                    iItem = new ToolStripMenuItemEx[fFile.Length];
                    foreach (FileInfo file in fFile)
                    {
                        iItem[i] = fileInfo(file, fFile.Length);
                        i++;
                    }
                    iParentItem.DropDownItems.AddRange(iItem);
                }
            }
        }
示例#3
0
        //Create and populate the contextmenu with files/folders of selected directory
        public void populateList(string sPath)
        {
            ContextMenuStrip cMenue = new ContextMenuStrip();
            DirectoryInfo nodeDirInfo = new DirectoryInfo(sPath);
            if (nodeDirInfo.Exists)
            {
                rootDir = sPath;
                int i = 0;
                ToolStripMenuItemEx[] iItem = new ToolStripMenuItemEx[nodeDirInfo.GetDirectories().Length];
                foreach (DirectoryInfo dir in nodeDirInfo.GetDirectories())
                {
                    iItem[i] = new ToolStripMenuItemEx(dir.Name,imageList.Images[0]);
                  //  iItem[i].ToolTipText = dir.FullName;
                    iItem[i].Path = dir.FullName;
                    if (System.Threading.Thread.CurrentThread.CurrentUICulture.ToString() == "de-DE")
                        iItem[i].ToolTipText = de[3]; //"Erstellt: "
                    else
                        iItem[i].ToolTipText = en[3];
                    iItem[i].ToolTipText += dir.CreationTime.ToString();
                    iItem[i].DropDownItems.Add("...");
                    iItem[i].DropDownOpening += new EventHandler(iItem_DropDownOpening);
                    Console.Write(iItem[i].Name + "\n");
                    i++;
                }

                cMenue.Items.AddRange(iItem);
                cMenue.DoubleClick += new EventHandler(DropDown_DoubleClick);
                cMenue.MouseClick += new MouseEventHandler(DropDown_MouseClick);
                iItem = new ToolStripMenuItemEx[nodeDirInfo.GetFiles().Length];
                i = 0;
                foreach (FileInfo file in nodeDirInfo.GetFiles())
                {
                    iItem[i] = fileInfo(file, iItem.Length);
                    i++;
                }
                cMenue.Items.AddRange(iItem);
                Rectangle rScreen = Screen.GetWorkingArea(f1);
                if (rScreen.Width + rScreen.X > f1.Location.X + xPos + cMenue.Width)
                    cMenue.Show(f1.Location.X + xPos, f1.Location.Y + yPos);
                else
                    cMenue.Show(f1.Location.X - cMenue.Width, f1.Location.Y + yPos);
            }
        }