⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pex.cs

📁 POCKET PC,照片管理系统!提供了真正意义上的目录打开功能
💻 CS
📖 第 1 页 / 共 2 页
字号:
            this.ilThumbnails = new System.Windows.Forms.ImageList();
            this.ilThumbnails.ImageSize = new System.Drawing.Size(10, 10);
            // 
            // lvThumb
            // 
            this.lvThumb = new System.Windows.Forms.ListView();
            this.lvThumb.Parent = this;
            this.lvThumb.ContextMenu = this.contextMenu;
            this.lvThumb.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
            this.lvThumb.LargeImageList = this.ilThumbnails;
            this.lvThumb.Location = new System.Drawing.Point(-1, -1);
            this.lvThumb.Size = new System.Drawing.Size(242, 272);
            this.lvThumb.SelectedIndexChanged += new System.EventHandler(this.OnSelectedImageChanged);

            this.Menu = this.menuPex;
        }
		#endregion

        #region --- HMI interaction ---
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad (e);
            Preferences.Singleton.Load();
            currentSelected = new DirectoryInfo(Preferences.Singleton.DefaultFolder);
            ProcessFolder();
        }

        private void OnToolbarClick(Object sender, ToolBarButtonClickEventArgs e)
        {
            switch(toolBar.Buttons.IndexOf(e.Button))
            {
                // Folder button
                case 1:
                    this.OnChangeFolder(this, null);
                    break;
                // Open button
                case 2:
                    this.OnOpen(this, null);
                    break;
                // Property button
                case 3:
                    this.OnProperty(this, null);
                    break;
                // Delete
                case 4:
                    this.OnDelete(this, null);
                    break;
            }

        }

        private void OnExit(object sender, System.EventArgs e)
        {
            this.Close();
        }

        private void OnOpen(object sender, System.EventArgs e)
        {
            if ( viewer == null )
            {
                viewer = new PictureViewer();
            }
//            viewer.PictureName = currentSelected.FullName + Path.DirectorySeparatorChar + this.GetSelectedItem().Text;
            viewer.ShowDialog();
        }

        private void OnSelectedImageChanged(object sender, System.EventArgs e)
        {
            //
            // Enable/Disable Menu items
            //
            ListView.SelectedIndexCollection selection = this.lvThumb.SelectedIndices;
            if( selection.Count == 1 )
            {
                this.tbbOpen.Enabled = true;
                this.miOpen.Enabled = true;
                this.miDelete.Enabled = true;
                this.miProperty.Enabled = true;
                this.tbbProperty.Enabled = true;
                this.tbbDelete.Enabled = true;
                this.miCtxDelete.Enabled = true;
                this.miCtxOpen.Enabled = true;
                this.miCtxProperty.Enabled = true;

	            ImageFileList.Singleton.Current = currentSelected.FullName + Path.DirectorySeparatorChar + this.GetSelectedItem().Text;
            }
            else
            {
                this.miOpen.Enabled = false;
                this.tbbOpen.Enabled = false;
                this.miDelete.Enabled = false;
                this.miProperty.Enabled = false;
                this.tbbProperty.Enabled = false;
                this.tbbDelete.Enabled = false;
                this.miCtxDelete.Enabled = false;
                this.miCtxOpen.Enabled = false;
                this.miCtxProperty.Enabled = false;
            }
        }

        private void OnProperty(object sender, System.EventArgs e)
        {
            PictureProperty prop = new PictureProperty();
            prop.ShowDialog();
        }

        private void OnChangeFolder(object sender, System.EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.Description = rm.GetString("PexTitle") + " - " + rm.GetString("ChooseFolder");
            fbd.SelectedPath = currentSelected.FullName;
            fbd.ShowDialog();

            if( fbd.DialogResult == DialogResult.OK )
            {
                Cursor.Current = Cursors.WaitCursor;
                DirectoryInfo NewSelected = new DirectoryInfo(fbd.SelectedPath);

                if( !currentSelected.FullName.Equals(NewSelected.FullName) )
                {
                    currentSelected = NewSelected;
                    ProcessFolder();
                }
                Cursor.Current = Cursors.Default;
            }
        }
        private void OnPreferences(object sender, System.EventArgs e)
        {
            PreferencesDialog PrefDlg = new PreferencesDialog();
            if( ( PrefDlg.ShowDialog() == DialogResult.OK ) && Preferences.Singleton.HasChanged )
            {
                ProcessFolder();
            }
        }
        private void OnDelete(object sender, System.EventArgs e)
        {
            string message = string.Format(rm.GetString("DeleteConfirmation"), ImageFileList.Singleton.Current);

            if ( MessageBox.Show(   message, 
                                    rm.GetString("DeletionCaption"),
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button2) == DialogResult.Yes )
            {
                File.Delete(ImageFileList.Singleton.Current);
				ImageFileList.Singleton.RemoveCurrent();
                lvThumb.Items.Remove(GetSelectedItem());
            }
        }

        private void OnAbout(object sender, System.EventArgs e)
        {
            new About().ShowDialog();
        }

        private void OnPexHelp(object sender, System.EventArgs e)
        {
            string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\help\Pex.htm";
            ShellExecute.Execute(path);            
        }
        #endregion
        
        private void ProcessFolder()
        {
            ImageFileList.Singleton.Clear();
			//
            // Display the name of the selected folder
            //
            this.Text = rm.GetString("PexTitle") + " - " + currentSelected.Name;

            this.ilThumbnails.ImageSize = new System.Drawing.Size((int)Preferences.Singleton.ThumbSize, (int)Preferences.Singleton.ThumbSize);
            this.ilThumbnails.Images.Clear();
            this.lvThumb.Clear();
		
            // Go through the list of files into the current folder,
            // and try to create a Bitmap object from each file,
            // if there is not thrown exception, display the bitmap into a little thumbnail
        
            FileInfo[] files = currentSelected.GetFiles();
            foreach(FileInfo file in files)
            {
                this.LoadImage(file);
            }
        }

        private void LoadImage(FileInfo imagePath)
        {
            try
            {
                //
                // Load the bitmap and create the thumb
                //
                Bitmap original = new Bitmap(imagePath.FullName);
                Bitmap thumb = ImageProcessor.GetThumbnailImage(
                    original,
                    this.ilThumbnails.ImageSize.Width,
                    this.ilThumbnails.ImageSize.Height,
                    Preferences.Singleton.DrawRectangle,
                    Preferences.Singleton.StrechSmallToThumbnails);

                original.Dispose();

                this.ilThumbnails.Images.Add(thumb);
		        
                //
                // Add the item to the list view
                //
                ListViewItem item = new ListViewItem(imagePath.Name);
                item.ImageIndex = this.ilThumbnails.Images.Count - 1;
                this.lvThumb.Items.Add(item);

				//
				// Add the file to the list
				//
				ImageFileList.Singleton.Add(imagePath.FullName);
            }
            catch(OutOfMemoryException e)
            {
                string message = string.Format(rm.GetString("TooBigPicture"), imagePath.Name);
                MessageBox.Show(message, 
                                rm.GetString("Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Hand,
                                MessageBoxDefaultButton.Button1);
            }
            catch(Exception e)
            {
            }
        }

        private ListViewItem GetSelectedItem()
        {
            // Get the index of the selected item
            ListView.SelectedIndexCollection selection = this.lvThumb.SelectedIndices;
            IEnumerator iterator = selection.GetEnumerator();
            iterator.MoveNext();
            int index = (int)iterator.Current;

            // Get the selected item
            ListViewItem selected = null;
            ListView.ListViewItemCollection items = this.lvThumb.Items;
            foreach(ListViewItem item in items)
            {
                if( ( item.Index == index ) && ( item.Selected ) )
                {
                    selected = item;
                    break;
                }
            }

            return selected;
        }

        public static void Main()
        {
            Application.Run(new Pex());
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -