Click here to Skip to main content
15,892,927 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.9K   8.3K   95  
Thumbnail and image viewing controls for Windows Forms, using C#.
using System;
using System.Windows.Forms;
using Attilan.Crystal.Controls;

namespace WaitFormPictureShow
{
    /// <summary>
    /// Demonstrates how to use both CrystalPictureShow and CrystalMemoryCollector to
    /// create a unique Wait dialog.
    /// </summary>
    public partial class WaitPictureShowForm : Form
    {
        #region Events

        /// <summary>
        /// Event that gets fired when user cancels the operation.
        /// </summary>
        public event EventHandler WaitTerminated;

        #endregion

        /// <summary>
        /// Default constructor
        /// </summary>
        public WaitPictureShowForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Handles the load event for the Form.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Effect arguments</param>
        private void WaitPictureShowForm_Load(object sender, EventArgs e)
        {
            // For an extra bit of flair, I am using the MRG Control Loading Circle
            // by Martin Gagne
            // See his article on CodeProject:
            // http://www.codeproject.com/cs/miscctrl/mrg_loadingcircle.asp
            loadingCircle1.Active = true;

            // Setting ImageSizeMode to ratio stretch means that the images
            // fit inside the control's client area with the proper proportions.
            crystalPictureShow1.ImageSizeMode = SizeMode.RatioStretch;

            // Create a new memory collector object.
            // Memory collector does not pick up images from the disk.
            // Instead, you must add the images yourself by calling AddImage.
            CrystalMemoryCollector memCollector = new CrystalMemoryCollector();

            // Now let's add the images
            // AddImage (full image, thumbnailed image, image name)
            // In this case, the thumbnailed image and the full image are the same thing.

            // This set of images are from the 1970s Marvel Value Stamps
            // http://www.mvstamps.com/
            memCollector.AddImage(StampRes.stamp_001, StampRes.stamp_001, "Spider-Man");
            memCollector.AddImage(StampRes.stamp_002, StampRes.stamp_002, "Hulk");
            memCollector.AddImage(StampRes.stamp_004, StampRes.stamp_004, "Thing");
            memCollector.AddImage(StampRes.stamp_009, StampRes.stamp_009, "Capt Marvel");
            memCollector.AddImage(StampRes.stamp_013, StampRes.stamp_013, "Dr. Strange");
            memCollector.AddImage(StampRes.stamp_023, StampRes.stamp_023, "Sgt Fury");
            memCollector.AddImage(StampRes.stamp_065, StampRes.stamp_065, "Iceman");
            memCollector.AddImage(StampRes.stamp_067, StampRes.stamp_067, "Cyclops");
            memCollector.AddImage(StampRes.stamp_068, StampRes.stamp_068, "Son of Satan");
            memCollector.AddImage(StampRes.stamp_071, StampRes.stamp_071, "Vision");
            memCollector.AddImage(StampRes.stamp_084, StampRes.stamp_084, "Dr. Doom");
            memCollector.AddImage(StampRes.stamp_087, StampRes.stamp_087, "Jonah Jameson");
            memCollector.AddImage(StampRes.stamp_088, StampRes.stamp_088, "Leader");
            memCollector.AddImage(StampRes.stamp_093, StampRes.stamp_093, "Silver Surfer");
            memCollector.AddImage(StampRes.stamp_100, StampRes.stamp_100, "Galactus");
            memCollector.AddImage(StampRes.stamp_101, StampRes.stamp_101, "Hulk");

            // This is from the 2006 set of US Post office DC Comics stamps.
            memCollector.AddImage(StampRes.stamp_dc_01, StampRes.stamp_dc_01, "Superman");
            memCollector.AddImage(StampRes.stamp_dc_02, StampRes.stamp_dc_02, "Green Lantern");
            memCollector.AddImage(StampRes.stamp_dc_03, StampRes.stamp_dc_03, "Batman");
            memCollector.AddImage(StampRes.stamp_dc_04, StampRes.stamp_dc_04, "Flash");

            // This is from the 2007 set of US Post office Marvel Comics stamps.
            memCollector.AddImage(StampRes.stamp_iron_man, StampRes.stamp_iron_man, "Iron Man");

            // Don't use the thumbnailer object in CrystalPictureShow
            // Instead, just load the thumbnails from the CrystalMemoryCollector
            crystalPictureShow1.UseThumbnailer = false;

            // Options set to:
            // Show images every second, randomize the image order, use the Fade effect.
            crystalPictureShow1.SlideShowOptions.ImageIntervalTime = 0.1f;
            crystalPictureShow1.SlideShowOptions.ShuffleMode = true;
            crystalPictureShow1.SlideShowOptions.SlideEffect = SlideShowEffect.Fade;

            // The slideshow is primed, the collector is locked and loaded.
            // Do the slideshow.
            crystalPictureShow1.StartSlideShow(memCollector, 0);
        }

        /// <summary>
        /// When the user clicks on the cancel button, we must respond.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Event arguments.</param>
        private void buttonWait_Click(object sender, EventArgs e)
        {
            if (WaitTerminated != null)
            {
                EventArgs eventArgs = new EventArgs();
                WaitTerminated(this, eventArgs);
            }
        }

        /// <summary>
        /// Handles the closing event by stopping the slide show.
        /// </summary>
        /// <param name="e">Event arguments.</param>
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            crystalPictureShow1.EndSlideShow();
            base.OnFormClosing(e);
        }
    }
}

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