Click here to Skip to main content
15,881,812 members
Articles / Desktop Programming / Windows Forms

Crystal Image Toolkit: thumbnail image control and picture viewing.

Rate me:
Please Sign up or sign in to vote.
4.68/5 (21 votes)
11 May 2011LGPL37 min read 109.4K   8.3K   95  
Thumbnail and image viewing controls for Windows Forms, using C#.
using System;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;
using Attilan.Crystal.Controls;
using Attilan.Crystal.Tools;

namespace ComicShowControllerDemo
{
    public partial class PSPExportForm : Form
    {
        public string LastPSPTargetFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);

        public CrystalComicShowController ComicController;

        private PSPUnpackWorker _unpackWorker = new PSPUnpackWorker();

        public PSPExportForm()
        {
            InitializeComponent();
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = LastPSPTargetFolder;
            if (folderBrowserDialog1.ShowDialog(this) == DialogResult.OK)
            {
                tbExportFolder.Text = folderBrowserDialog1.SelectedPath;
                LastPSPTargetFolder = folderBrowserDialog1.SelectedPath;
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(tbExportFolder.Text))
                {
                    if (!Directory.Exists(tbExportFolder.Text))
                    {
                        Directory.CreateDirectory(tbExportFolder.Text);
                    }
                }                
            }
            catch (Exception ex)
            {
                CrystalLogger.LogException("Export button in PSP form", ex);
                MessageBox.Show(this, ex.Message, "Director error");
                return;
            }

            LastPSPTargetFolder = tbExportFolder.Text;

            btnSelect.Enabled = false;
            btnOK.Enabled = false;
            tbExportFolder.Enabled = false;

            _unpackWorker.UnpackLocation = tbExportFolder.Text;
            _unpackWorker.Collector = ComicController.Collector;
            _unpackWorker.ProgressChanged += new ProgressChangedEventHandler(unpackWorker_ProgressChanged);
            _unpackWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(unpackWorker_RunWorkerCompleted);
            _unpackWorker.RunWorkerAsync();
        }

        void unpackWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            progressBar1.Value = progressBar1.Maximum;
            DialogResult = DialogResult.OK;
        }

        void unpackWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            try
            {
                progressBar1.Value = e.ProgressPercentage;
            }
            catch(Exception ex)
            {
                CrystalLogger.LogException("unpackWorker_ProgressChanged", ex);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (_unpackWorker.IsBusy)
            {
                _unpackWorker.CancelAsync();
            }

            DialogResult = DialogResult.Cancel;
        }

        private void PSPExportForm_Load(object sender, EventArgs e)
        {
            tbExportFolder.Text = LastPSPTargetFolder;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer (Senior)
United States United States
Richard has been working with Windows software since 1991. He has worked for Borland, Microsoft, Oracle, and various startup companies such as Livescribe. Currently he is developing projects in C#, Windows Forms, and Net Framework. Visit his blog Attilan (www.attilan.com) to learn more about his tools, projects and discoveries.

Comments and Discussions