Click here to Skip to main content
15,885,309 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.6K   8.3K   95  
Thumbnail and image viewing controls for Windows Forms, using C#.
#region gnu_license

/*
    Crystal Controls - C# control library containing the following tools:
        CrystalControl - base class
        CrystalGradientControl - a control that can either have a gradient background or be totally transparent.
        CrystalLabel - a homegrown label that can have a gradient or transparent background.
        CrystalPanel - a panel that can have a gradient or transparent background.
        CrystalTrackBar - a homegrown trackbar that can have a gradient or transparent background.
        CrystalToolStripTrackBar - a host for CrystalTrackBar that allows it to work in a ToolStrip.
        
        CrystalImageGridView - a control that hosts thumbnail images in a virtual grid.
        CrystalImageGridModel - a data model that holds a collection of CrystalImageItems
                                to feed to CrystalImageGridView.
        CrystalImageItem - a class that describes an Image file.
        CrystalThumbnailer - provides thumbnailing methods for images.

        CrystalCollector - a base class for a controller that links 
                            CrystalImageGridView to the CrystalImageGridModel.
        CrystalFileCollector - a controller that works on disk-based Image files.
        CrystalDesignCollector - a controller that works in Visual Studio toolbox designer.
        CrystalMemoryCollector - a controller that can be used to add images from memory.
        CrystalMemoryZipCollector - a controller that accesses images in zip files by streaming them into memory.
        CrystalZipCollector - a controller that accesses images in zip files by unpacking them.
        CrystalRarCollector - a controller that accesses images in rar files by unpacking them.

        CrystalPictureBox - a picture box control, derived from CrystalGradientControl.
        CrystalPictureShow - a control for viewing images and processing slideshows.
        CrystalComicShow - a control for viewing comic-book images in the CDisplay format.
 
    Copyright (C) 2006, 2008 Richard Guion
    Attilan Software Factory: http://www.attilan.com
    Contact: richard@attilan.com

   Version 1.0.0
        This is a work in progress: USE AT YOUR OWN RISK!  Interfaces/Methods may change!
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#endregion

using System;
using System.ComponentModel;

namespace Attilan.Tools
{
    /// <summary>
    /// Helper class to call EventHandlers with a level of thread safety.
    /// </summary>
    public static class EventNotifier
    {
        /// <summary>
        /// Updates a single event handler with thread safety.
        /// </summary>
        /// <param name="singleCast">EventHandler object.</param>
        /// <param name="eventArgs">Event arguments to dispatch to the event handler.</param>
        /// <param name="sender">Object sending the message.</param>
        public static void UpdateSingleEventHandler(EventHandler singleCast,
                                                EventArgs eventArgs, object sender)
        {
            if (singleCast == null)
            {
                return;
            }

            ISynchronizeInvoke syncInvoke =
                      singleCast.Target as ISynchronizeInvoke;
            //try
            //{
                if ((syncInvoke != null) && (syncInvoke.InvokeRequired))
                    syncInvoke.Invoke(singleCast,
                                  new object[] { sender, eventArgs });
                else
                    singleCast(sender, eventArgs);
            //}
            //catch (Exception ex)
            //{
            //    CrystalLogger.LogException("Exception in UpdateSingleEventHandler: {0}", ex);
            //}

            /*
            if (singleCast.Target is Control)
            {
                Control targetControl = (Control)singleCast.Target;
                if ((targetControl != null) && (targetControl.IsHandleCreated))
                    targetControl.Invoke(singleCast, new object[] { sender, eventArgs });
            }
            else
            {
                singleCast(sender, eventArgs);
            }
             */
        }

        /// <summary>
        /// Updates all delegates in the event handler's invocation list with a level of thread safety.
        /// </summary>
        /// <param name="masterHandler">Event Handler object containing an invocation list.</param>
        /// <param name="args">Event arguments to dispatch.</param>
        /// <param name="sender">Object sending the message.</param>
        public static void UpdateSubscribers(EventHandler masterHandler, EventArgs args, object sender)
        {
            if (masterHandler != null)
            {
                // makes the method thread safe. I get a local copy of the event handler and make sure 
                // that even if somebody modifies the Event there won't be any trouble.
                EventHandler handler = masterHandler;

                foreach (EventHandler singleCast in handler.GetInvocationList())
                {
                    UpdateSingleEventHandler(singleCast, args, sender);
                }
            }
        }
    }
}

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