Click here to Skip to main content
15,894,343 members
Articles / Programming Languages / C# 4.0

EasyProgressBarPacket

Rate me:
Please Sign up or sign in to vote.
4.84/5 (42 votes)
18 Nov 2011CPOL4 min read 67.2K   6.9K   105  
A few progressbar examples with clone support.
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.ComponentModel;
using System.Windows.Forms;

namespace TestApplication
{
    public partial class AnimatedStripControls : Form
    {
        public AnimatedStripControls()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!aniEasyProgressTaskManager1.IsWorking)
            {
                aniEasyProgressTaskManager1.Start(toolStripAnimatedEasyProgressBarItem1.Control);
                status.Text = "Please wait while the task is running.";
                button1.Text = "Stop Running Tasks";
            }
            else
            {
                aniEasyProgressTaskManager1.StopTask();
                status.Text = "task stopped.";
                button1.Text = "Start Examples";
            }

            if (!aniEasyProgressTaskManager2.IsWorking)
            {
                aniEasyProgressTaskManager2.Start(toolStripAnimatedEasyProgressBarItem2.Control);
            }
            else
            {
                aniEasyProgressTaskManager2.StopTask();
            }

            if (!aniEasyProgressTaskManager3.IsWorking)
            {
                aniEasyProgressTaskManager3.Start(toolStripAnimatedEasyProgressBarItem3.Control);
            }
            else
            {
                aniEasyProgressTaskManager3.StopTask();
            }

            if (!aniEasyProgressTaskManager4.IsWorking)
            {
                aniEasyProgressTaskManager4.Start(toolStripAnimatedEasyProgressBarItem4.Control);
            }
            else
            {
                aniEasyProgressTaskManager4.StopTask();
            }
        }

        private void AnimatedStripControls_Load(object sender, EventArgs e)
        {
            toolStripAnimatedEasyProgressBarItem2.AnimatedProgressBar.FrameChanged += new EventHandler<EasyProgressBarPacket.Components.ReportTaskProgressEventArgs>(Green_FrameChanged);
            toolStripAnimatedEasyProgressBarItem3.AnimatedProgressBar.FrameChanged += new EventHandler<EasyProgressBarPacket.Components.ReportTaskProgressEventArgs>(Blue_FrameChanged);
            toolStripAnimatedEasyProgressBarItem4.AnimatedProgressBar.FrameChanged += new EventHandler<EasyProgressBarPacket.Components.ReportTaskProgressEventArgs>(Red_FrameChanged);
        }

        void Green_FrameChanged(object sender, EasyProgressBarPacket.Components.ReportTaskProgressEventArgs e)
        {
            Size bitmapSize = e.GetActiveFrameImage.Size;

            // Create a new empty image for manipulations. If you use this constructor, you get a new Bitmap object that represents a bitmap in memory with a PixelFormat of Format32bppARGB.
            using (Bitmap overlay = new Bitmap(bitmapSize.Width, bitmapSize.Height), 
                overlay2 = new Bitmap(bitmapSize.Width, bitmapSize.Height))
            {
                // Make an associated Graphics object.
                using (Graphics bmpGraphics = Graphics.FromImage(overlay2))
                {
                    bmpGraphics.DrawImageUnscaled(e.GetActiveFrameImage, Point.Empty);
                }

                // Make an associated Graphics object.
                using (Graphics bmpGraphics = Graphics.FromImage(overlay))
                {
                    /* Create a new color matrix,
                        The value Alpha in row 4, column 4 specifies the alpha value */
                    float[][] jaggedMatrix = new float[][]
                    {
                        // Red component   [from 0.0 to 1.0 increase red color component.]
                        new float[]{ 0.6f , 0.0f , 0.0f , 0.0f , 0.0f },                  
                        // Green component [from 0.0 to 1.0 increase green color component.]
                        new float[]{ 0.0f , 0.9f , 0.0f , 0.0f , 0.0f },                
                        // Blue component  [from 0.0 to 1.0 increase blue color component.]
                        new float[]{ 0.0f , 0.0f , 0.6f , 0.0f , 0.0f },                 
                        // Alpha component [from 1.0 to 0.0 increase transparency bitmap.]
                        new float[]{ 0.0f , 0.0f , 0.0f , 1.0f , 0.0f },       
                        // White component [0.0: goes to Original color, 1.0: goes to white for all color component(Red, Green, Blue.)]
                        new float[]{ 0.2f , 0.2f , 0.2f , 0.0f , 1.0f }                                                                                           
                    };

                    ColorMatrix colorMatrix = new ColorMatrix(jaggedMatrix);

                    // Create an ImageAttributes object and set its color matrix
                    using (ImageAttributes attributes = new ImageAttributes())
                    {
                        attributes.SetColorMatrix(
                            colorMatrix,
                            ColorMatrixFlag.Default,
                            ColorAdjustType.Bitmap);

                        bmpGraphics.DrawImage(overlay2, new Rectangle(Point.Empty, new Size(overlay2.Width, overlay2.Height)), 0, 0, overlay2.Width, overlay2.Height, GraphicsUnit.Pixel, attributes);
                    }
                }

                e.GetActiveFrameImage = (Bitmap)overlay.Clone();
            }
        }

        void Blue_FrameChanged(object sender, EasyProgressBarPacket.Components.ReportTaskProgressEventArgs e)
        {
            Size bitmapSize = e.GetActiveFrameImage.Size;

            // Create a new empty image for manipulations. If you use this constructor, you get a new Bitmap object that represents a bitmap in memory with a PixelFormat of Format32bppARGB.
            using (Bitmap overlay = new Bitmap(bitmapSize.Width, bitmapSize.Height),
                overlay2 = new Bitmap(bitmapSize.Width, bitmapSize.Height))
            {
                // Make an associated Graphics object.
                using (Graphics bmpGraphics = Graphics.FromImage(overlay2))
                {
                    bmpGraphics.DrawImageUnscaled(e.GetActiveFrameImage, Point.Empty);
                }

                // Make an associated Graphics object.
                using (Graphics bmpGraphics = Graphics.FromImage(overlay))
                {
                    /* Create a new color matrix,
                        The value Alpha in row 4, column 4 specifies the alpha value */
                    float[][] jaggedMatrix = new float[][]
                    {
                        // Red component   [from 0.0 to 1.0 increase red color component.]
                        new float[]{ 0.6f , 0.0f , 0.0f , 0.0f , 0.0f },                  
                        // Green component [from 0.0 to 1.0 increase green color component.]
                        new float[]{ 0.0f , 0.6f , 0.0f , 0.0f , 0.0f },                
                        // Blue component  [from 0.0 to 1.0 increase blue color component.]
                        new float[]{ 0.0f , 0.0f , 0.9f , 0.0f , 0.0f },                 
                        // Alpha component [from 1.0 to 0.0 increase transparency bitmap.]
                        new float[]{ 0.0f , 0.0f , 0.0f , 1.0f , 0.0f },       
                        // White component [0.0: goes to Original color, 1.0: goes to white for all color component(Red, Green, Blue.)]
                        new float[]{ 0.2f , 0.2f , 0.2f , 0.0f , 1.0f }                                                                                           
                    };

                    ColorMatrix colorMatrix = new ColorMatrix(jaggedMatrix);

                    // Create an ImageAttributes object and set its color matrix
                    using (ImageAttributes attributes = new ImageAttributes())
                    {
                        attributes.SetColorMatrix(
                            colorMatrix,
                            ColorMatrixFlag.Default,
                            ColorAdjustType.Bitmap);

                        bmpGraphics.DrawImage(overlay2, new Rectangle(Point.Empty, new Size(overlay2.Width, overlay2.Height)), 0, 0, overlay2.Width, overlay2.Height, GraphicsUnit.Pixel, attributes);
                    }
                }

                e.GetActiveFrameImage = (Bitmap)overlay.Clone();
            }
        }

        void Red_FrameChanged(object sender, EasyProgressBarPacket.Components.ReportTaskProgressEventArgs e)
        {
            Size bitmapSize = e.GetActiveFrameImage.Size;

            // Create a new empty image for manipulations. If you use this constructor, you get a new Bitmap object that represents a bitmap in memory with a PixelFormat of Format32bppARGB.
            using (Bitmap overlay = new Bitmap(bitmapSize.Width, bitmapSize.Height),
                overlay2 = new Bitmap(bitmapSize.Width, bitmapSize.Height))
            {
                // Make an associated Graphics object.
                using (Graphics bmpGraphics = Graphics.FromImage(overlay2))
                {
                    bmpGraphics.DrawImageUnscaled(e.GetActiveFrameImage, Point.Empty);
                }

                // Make an associated Graphics object.
                using (Graphics bmpGraphics = Graphics.FromImage(overlay))
                {
                    /* Create a new color matrix,
                        The value Alpha in row 4, column 4 specifies the alpha value */
                    float[][] jaggedMatrix = new float[][]
                    {
                        // Red component   [from 0.0 to 1.0 increase red color component.]
                        new float[]{ 0.9f , 0.0f , 0.0f , 0.0f , 0.0f },                  
                        // Green component [from 0.0 to 1.0 increase green color component.]
                        new float[]{ 0.0f , 0.6f , 0.0f , 0.0f , 0.0f },                
                        // Blue component  [from 0.0 to 1.0 increase blue color component.]
                        new float[]{ 0.0f , 0.0f , 0.6f , 0.0f , 0.0f },                 
                        // Alpha component [from 1.0 to 0.0 increase transparency bitmap.]
                        new float[]{ 0.0f , 0.0f , 0.0f , 1.0f , 0.0f },       
                        // White component [0.0: goes to Original color, 1.0: goes to white for all color component(Red, Green, Blue.)]
                        new float[]{ 0.2f , 0.2f , 0.2f , 0.0f , 1.0f }                                                                                           
                    };

                    ColorMatrix colorMatrix = new ColorMatrix(jaggedMatrix);

                    // Create an ImageAttributes object and set its color matrix
                    using (ImageAttributes attributes = new ImageAttributes())
                    {
                        attributes.SetColorMatrix(
                            colorMatrix,
                            ColorMatrixFlag.Default,
                            ColorAdjustType.Bitmap);

                        bmpGraphics.DrawImage(overlay2, new Rectangle(Point.Empty, new Size(overlay2.Width, overlay2.Height)), 0, 0, overlay2.Width, overlay2.Height, GraphicsUnit.Pixel, attributes);
                    }
                }

                e.GetActiveFrameImage = (Bitmap)overlay.Clone();
            }
        }
    }
}

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 Code Project Open License (CPOL)


Written By
Software Developer (Senior) ARELTEK
Turkey Turkey
Since 1998...

MCPD - Enterprise Application Developer

“Hesaplı hareket ettiğini zanneden ve onunla iftihar eyliyen dar kafalar; kurtulmağa, yükselmeğe elverişli hiç bir eser vücüda getirmezler. Kurtuluş ve yükselişi, ancak varlığına dayanan ve mülkü milletin gizli kapalı hazinelerini verimli hale getirmesini bilen, şahsi menfaatini millet menfaati uğruna feda eden, ruhu idealist, dimağı realist şahsiyetlerde aramalıdır.”

Nuri Demirağ, 1947

Comments and Discussions