PhilBayley Posted December 29, 2003 Posted December 29, 2003 My apologies if this is simple to solve but I am having problems with the forecolor of my progress bar. I want it to be blue but it just wont change. I have positioned my progress bar onto my statusbar and it works fine but it just wont go blue. Can anyone see whats wrong. this code is in the forms contructor Thanks Phil InitializeComponent(); progressBar2 = new System.Windows.Forms.ProgressBar(); progressBar2.Parent = statusBar1; progressBar2.ForeColor = Color.Blue; progressBar2.Left = 3; progressBar2.Top = 3; progressBar2.Width = 260; progressBar2.Height = 18; Quote
Leeus Posted December 29, 2003 Posted December 29, 2003 You can't just reference the color.blue directly, you can if you imported system.drawing Otherwise it would be system.drawing.color.blue. Quote
PhilBayley Posted December 29, 2003 Author Posted December 29, 2003 Yep I did import the system.drawing stuff and Ive also tried it your way but with no luck it still remains grey. Quote
XxBartmanxX Posted December 29, 2003 Posted December 29, 2003 Are you 100% sure that it is enabled? Quote
samsmithnz Posted December 29, 2003 Posted December 29, 2003 Even though these color properties are there, you can't use them like this. The control doesn't do anything with these properties. Personally I think that the progressbar is the worst control in .NET. It seems to be missing several key features (like displaying text/% overlaying the progress bar, a 'smooth' progress bar option, and being able to change the colors as you've just discovered. I hope they fix this soon! Quote Thanks Sam http://www.samsmith.co.nz
PhilBayley Posted December 29, 2003 Author Posted December 29, 2003 Ummm - Im not sure. I know that it is in place where it should be and when I change the value property from another function, the progressbar increments as it should. The only thing it wont do is change colour. :-) Quote
Leaders dynamic_sysop Posted December 29, 2003 Leaders Posted December 29, 2003 here's the link to an example i made a long time ago in c# for colouring a progressbar ... colouring a progressbar in C# it allows you to colour the back and front :) Quote
PhilBayley Posted December 29, 2003 Author Posted December 29, 2003 Even though these color properties are there, you can't use them like this. The control doesn't do anything with these properties. Personally I think that the progressbar is the worst control in .NET. It seems to be missing several key features (like displaying text/% overlaying the progress bar, a 'smooth' progress bar option, and being able to change the colors as you've just discovered. I hope they fix this soon! Hey thanks for this - at least I know that its not me now! Quote
samsmithnz Posted December 29, 2003 Posted December 29, 2003 here's the link to an example i made a long time ago in c# for colouring a progressbar ... colouring a progressbar in C# it allows you to colour the back and front :) How does this work? And why can't we do this in VB.NET? Quote Thanks Sam http://www.samsmith.co.nz
Leaders dynamic_sysop Posted December 29, 2003 Leaders Posted December 29, 2003 we can do this in vb.net :) if i get time between feeding duties i'll knock you up an example. Quote
Leaders dynamic_sysop Posted December 29, 2003 Leaders Posted December 29, 2003 ok i translated it over roughly, here ya go... Public Const PBM_SETBARCOLOR As Integer = &H409 Public Const PBM_SETBKCOLOR As Integer = &H2001 Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SetProgressBackColor(ProgressBar1, Color.Red) SetProgressForeColor(ProgressBar1, Color.Blue) End Sub Public Sub SetProgressBackColor(ByVal pb As ProgressBar, ByVal c As Color) '/// set the back color of the bar Dim a As Integer = Convert.ToInt32(c.R) Dim b As Integer = Convert.ToInt32(c.G) Dim d As Integer = Convert.ToInt32(c.B) Dim tot As Integer = ColorTranslator.ToWin32(Color.FromArgb(a, b, d)) SendMessage(pb.Handle, PBM_SETBKCOLOR, 0, tot) End Sub Public Sub SetProgressForeColor(ByVal pb As ProgressBar, ByVal c As Color) '/// set the back color of the bar Dim a As Integer = Convert.ToInt32(c.R) Dim b As Integer = Convert.ToInt32(c.G) Dim d As Integer = Convert.ToInt32(c.B) Dim tot As Integer = ColorTranslator.ToWin32(Color.FromArgb(a, b, d)) SendMessage(pb.Handle, PBM_SETBARCOLOR, 0, tot) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click With ProgressBar1 .Maximum = 100 .Value = 50 '/// test forecolor. End With End Sub Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.