Results 1 to 2 of 2

Thread: colouring a progressbar in C#

  1. #1

    Thread Starter
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Smile colouring a progressbar in C#

    hi i created a little bit of code for colouring progressbars ( back and forecolor )
    Code:
    using System.Runtime.InteropServices;
    ///// at top of code window ^^^^^^^
    /////
    		[DllImport("User32.Dll")]
            public static extern int SendMessage(int hwnd,int wMsg,int wParam,int lParam);
            
    		public const int PBM_SETBKCOLOR = 0x2001;
            public const int PBM_SETBARCOLOR = 0x409;
    ///// in designer area ^^^^^^^^
    /////
    ////
    		public void SetProgressBackColor(Color c)
    		{/// set the back color of the bar
            int a=Convert.ToInt32(c.R.ToString());
    		int b=Convert.ToInt32(c.G.ToString());
    		int d=Convert.ToInt32(c.B.ToString());
            int tot=Convert.ToInt32(ColorTranslator.ToOle(Color.FromArgb(a,b,d)).ToString());
    		int j=this.progressBar1.Handle.ToInt32();
            SendMessage(j,PBM_SETBKCOLOR,0,tot);
    		}
    
    		public void SetProgressForeColor(Color c)
    		{/// set the forecolor of the bar
    			int a=Convert.ToInt32(c.R.ToString());
    			int b=Convert.ToInt32(c.G.ToString());
    			int d=Convert.ToInt32(c.B.ToString());
    			int tot=Convert.ToInt32(ColorTranslator.ToOle(Color.FromArgb(a,b,d)).ToString());
    			int j=this.progressBar1.Handle.ToInt32();
    			SendMessage(j,PBM_SETBARCOLOR,0,tot);
    		}
    		private void button4_Click(object sender, System.EventArgs e)
    		{//// set colour to your choice.
    			SetProgressBackColor(System.Drawing.Color.BlueViolet);
                SetProgressForeColor(System.Drawing.Color.Red);
    		}
    to test :
    Code:
    		private void button1_Click(object sender, System.EventArgs e)
    		{
    			this.progressBar1.Minimum = 1;
    			this.progressBar1.Maximum = 10000;
    			this.progressBar1.Step = 1;
    			this.progressBar1.Value = 1;
    			for(int i=progressBar1.Minimum; i<=progressBar1.Maximum; i++)
    			{
    				progressBar1.PerformStep();  
    			}
    		}
    obviously naming your controls as nessacary

  2. #2
    New Member
    Join Date
    Aug 2006
    Posts
    1

    Re: colouring a progressbar in C#

    THANK YOU VERY MUCH!!!!

    YOU SAVE MY DAY...

    Live VERY Long and Prosper...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width