Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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;

Posted

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!

Posted
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. :-)
Posted
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!

  • Leaders
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...