Click here to Skip to main content
15,892,199 members
Articles / Desktop Programming / Windows Forms

Converting Icons to Images with a Background Worker

Rate me:
Please Sign up or sign in to vote.
4.00/5 (5 votes)
25 Oct 2010CPOL2 min read 30.6K   463   14  
Using a background worker thread to execute a time consuming task
namespace IconToImage
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.lstfileList = new System.Windows.Forms.ListBox();
            this.btnSelectSome = new System.Windows.Forms.Button();
            this.btnSelectFolder = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.rtbReport = new System.Windows.Forms.RichTextBox();
            this.pgbFile = new System.Windows.Forms.ProgressBar();
            this.btnConvert = new System.Windows.Forms.Button();
            this.pgbIcon = new System.Windows.Forms.ProgressBar();
            this.bgw = new System.ComponentModel.BackgroundWorker();
            this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
            this.SuspendLayout();
            // 
            // lstfileList
            // 
            this.lstfileList.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lstfileList.FormattingEnabled = true;
            this.lstfileList.Location = new System.Drawing.Point(12, 12);
            this.lstfileList.Name = "lstfileList";
            this.lstfileList.Size = new System.Drawing.Size(298, 69);
            this.lstfileList.TabIndex = 0;
            // 
            // btnSelectSome
            // 
            this.btnSelectSome.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnSelectSome.Image = global::IconToImage.Properties.Resources.image_x_generic;
            this.btnSelectSome.Location = new System.Drawing.Point(12, 87);
            this.btnSelectSome.Name = "btnSelectSome";
            this.btnSelectSome.Size = new System.Drawing.Size(128, 31);
            this.btnSelectSome.TabIndex = 1;
            this.btnSelectSome.Text = "Select some icon";
            this.btnSelectSome.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
            this.btnSelectSome.UseVisualStyleBackColor = true;
            this.btnSelectSome.Click += new System.EventHandler(this.btnSelectSome_Click);
            // 
            // btnSelectFolder
            // 
            this.btnSelectFolder.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnSelectFolder.Image = global::IconToImage.Properties.Resources.folder_open;
            this.btnSelectFolder.Location = new System.Drawing.Point(172, 87);
            this.btnSelectFolder.Name = "btnSelectFolder";
            this.btnSelectFolder.Size = new System.Drawing.Size(138, 31);
            this.btnSelectFolder.TabIndex = 2;
            this.btnSelectFolder.Text = "Select icon\'s folder";
            this.btnSelectFolder.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
            this.btnSelectFolder.UseVisualStyleBackColor = true;
            this.btnSelectFolder.Click += new System.EventHandler(this.btnSelectFolder_Click);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1.Location = new System.Drawing.Point(146, 95);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(20, 13);
            this.label1.TabIndex = 3;
            this.label1.Text = "Or";
            // 
            // rtbReport
            // 
            this.rtbReport.Location = new System.Drawing.Point(12, 124);
            this.rtbReport.Name = "rtbReport";
            this.rtbReport.ReadOnly = true;
            this.rtbReport.Size = new System.Drawing.Size(298, 96);
            this.rtbReport.TabIndex = 4;
            this.rtbReport.Text = "";
            // 
            // pgbFile
            // 
            this.pgbFile.Location = new System.Drawing.Point(12, 233);
            this.pgbFile.Name = "pgbFile";
            this.pgbFile.Size = new System.Drawing.Size(217, 10);
            this.pgbFile.Step = 1;
            this.pgbFile.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
            this.pgbFile.TabIndex = 5;
            // 
            // btnConvert
            // 
            this.btnConvert.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnConvert.Image = global::IconToImage.Properties.Resources.view_refresh;
            this.btnConvert.Location = new System.Drawing.Point(235, 226);
            this.btnConvert.Name = "btnConvert";
            this.btnConvert.Size = new System.Drawing.Size(75, 33);
            this.btnConvert.TabIndex = 6;
            this.btnConvert.Text = "Convert";
            this.btnConvert.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
            this.btnConvert.UseVisualStyleBackColor = true;
            this.btnConvert.Click += new System.EventHandler(this.btnConvert_Click);
            // 
            // pgbIcon
            // 
            this.pgbIcon.Location = new System.Drawing.Point(12, 249);
            this.pgbIcon.Name = "pgbIcon";
            this.pgbIcon.Size = new System.Drawing.Size(217, 10);
            this.pgbIcon.Step = 1;
            this.pgbIcon.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
            this.pgbIcon.TabIndex = 7;
            // 
            // bgw
            // 
            this.bgw.WorkerReportsProgress = true;
            this.bgw.DoWork += new System.ComponentModel.DoWorkEventHandler(this.bgw_DoWork);
            this.bgw.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bgw_RunWorkerCompleted);
            this.bgw.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.bgw_ProgressChanged);
            // 
            // openFileDialog1
            // 
            this.openFileDialog1.FileName = "icon";
            this.openFileDialog1.Multiselect = true;
            this.openFileDialog1.Title = "select icon(s)";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(322, 266);
            this.Controls.Add(this.pgbIcon);
            this.Controls.Add(this.btnConvert);
            this.Controls.Add(this.pgbFile);
            this.Controls.Add(this.rtbReport);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.btnSelectFolder);
            this.Controls.Add(this.btnSelectSome);
            this.Controls.Add(this.lstfileList);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "Form1";
            this.Text = "Icon to image converter";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.ListBox lstfileList;
        private System.Windows.Forms.Button btnSelectSome;
        private System.Windows.Forms.Button btnSelectFolder;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.RichTextBox rtbReport;
        private System.Windows.Forms.ProgressBar pgbFile;
        private System.Windows.Forms.Button btnConvert;
        private System.Windows.Forms.ProgressBar pgbIcon;
        private System.ComponentModel.BackgroundWorker bgw;
        private System.Windows.Forms.OpenFileDialog openFileDialog1;
        private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
    }
}

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
Engineer Donatus Inc.
Indonesia Indonesia
I'm currently a student of Brawijaya University. I work on programming just for hobby. I learn programming since 2nd year of my college. That's when I first bought my PC on year 2004.

Comments and Discussions