Click here to Skip to main content
15,892,927 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.1K   6.9K   105  
A few progressbar examples with clone support.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

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

        private void btnExit_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void ProgressBarSample_Load(object sender, EventArgs e)
        {
            borderComboBox.SelectedIndex = 0;

            Win32.SetWindowTheme(vTextBox.Handle, String.Empty, String.Empty);
            Win32.SetWindowTheme(dspTextBox.Handle, String.Empty, String.Empty);
            borderComboBox.FlatStyle = FlatStyle.System;
            Win32.SetWindowTheme(borderComboBox.Handle, String.Empty, String.Empty);
            chkColorizer.FlatStyle = FlatStyle.System;
            Win32.SetWindowTheme(chkColorizer.Handle, String.Empty, String.Empty);

            foreach (Control control in this.Controls)
            {
                if (control is Button)
                {
                    ((Button)control).FlatStyle = FlatStyle.System;
                    Win32.SetWindowTheme(control.Handle, String.Empty, String.Empty);
                }
            }
        }

        private void UpdateProgress()
        {
            try
            {
                string format = dspTextBox.Text;
                int value = Convert.ToInt32(vTextBox.Text);
                EasyProgressBarPacket.EasyProgressBarBorderStyle borderStyle;
                switch (borderComboBox.Text)
                {
                    case "Raised":
                        borderStyle = EasyProgressBarPacket.EasyProgressBarBorderStyle.Raised;
                        break;
                    case "Sunken":
                        borderStyle = EasyProgressBarPacket.EasyProgressBarBorderStyle.Sunken;
                        break;
                    default:
                        borderStyle = EasyProgressBarPacket.EasyProgressBarBorderStyle.Flat;
                        break;
                }

                Color color1 = lblColor1.BackColor;
                Color color2 = lblColor2.BackColor;

                easyProgressBar1.DisplayFormat = format;
                easyProgressBar1.Value = value;
                easyProgressBar1.ControlBorderStyle = borderStyle;
                easyProgressBar1.ProgressGradient.ColorStart = color1;
                easyProgressBar1.ProgressGradient.ColorEnd = color2;
                easyProgressBar1.ProgressColorizer.IsColorizerEnabled = chkColorizer.Checked;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            dspTextBox.Text = "done";
            vTextBox.Text = "20";
            borderComboBox.SelectedIndex = 0;
            lblColor1.BackColor = Color.LightSteelBlue;
            lblColor2.BackColor = Color.LightBlue;
            chkColorizer.Checked = false;
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            UpdateProgress();
        }

        private void lblColor1_Click(object sender, EventArgs e)
        {
            this.colorDialog1.Color = lblColor1.BackColor;
            if (this.colorDialog1.ShowDialog() != DialogResult.OK)
                return;
            lblColor1.BackColor = this.colorDialog1.Color;
        }

        private void lblColor2_Click(object sender, EventArgs e)
        {
            this.colorDialog1.Color = lblColor2.BackColor;
            if (this.colorDialog1.ShowDialog() != DialogResult.OK)
                return;
            lblColor2.BackColor = this.colorDialog1.Color;
        }
    }
}

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