How to change back color of statusbar.

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

Is there a way to change the back color of the winforms status bar? My
forms use a custom back color and the gray color of the status bar sticks
out like a sore thumb.

Thanks.
 
Hi moondaddy,

Just like the link provided by Herfried, there is no build-in way for this,
the correct way is owner-draw it ourselves. But it seems that the url
provided by Herfried is German google link. Actually, there is KB showing
the sample of doing this, please refer to:
"HOW TO: Change the Color and the Font of the StatusBarPanel Object by
Using Visual C# .NET"
http://support.microsoft.com/default.aspx?id=319311
====================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thanks. That was a good start, but now how do I change the color of the
status bar itself and not just the panels? I need to change the color of
the entire bar to a very light blue and I still need to see the panel
borders. in other words, where the status bar is gray now, and the panels
have darker gray lines, I need to change everything to a very light blue and
the panel borders (and diagonals on the bottom right corner to a slightly
darker blue).

Can you advise on this?

Thanks.
 
Hi moondaddy,

For this issue, I will spend some time on it, I will reply to you ASAP.
Thanks for your understanding!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi moondaddy,

Sorry for letting you wait for so long.

To change the backcolor of the statusbar, we should do the custom drawing
ourselves. Note that, when we decided to do the custom drawing, we have to
handle the painting of the whole area of statusbar, and the setting in
statusbarpanel will take no effect, so if you need statusbarpanel, we
should paint it ourselves either.

The way of openning custom painting is overriding the statusbar class and
use Control.SetStyle to add ControlStyles.UserPaint bit to statusbar
control. Code snippet lists below:
public class MyStatusBar : System.Windows.Forms.StatusBar
{
public MyStatusBar()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,
true);
this.UpdateStyles();
}

protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillRectangle(new SolidBrush(Color.Blue), 0, 0, this.Width,
this.Height);
e.Graphics.DrawString("customized drawing", new Font("Arial", 10), new
SolidBrush(Color.Red), this.ClientRectangle, new StringFormat());
ControlPaint.DrawBorder(e.Graphics, 0, 0, this.Width, this.Height);
base.OnPaint (e);
}
£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thanks Jeffrey,

I used an online translation tool to convert the 2nd part of your code and 2
lines didn't compile:

Protected Overloads Overrides Sub OnPaint(ByVal e As PaintEventArgs)

e.Graphics.FillRectangle(New SolidBrush(Color.Blue), 0, 0, _

Me.Width, Me.Height)

'This line didn't compile

e.Graphics.DrawString("customized drawing", New Font("Arial", 10), _

New SolidBrush(Color.Red), Me.ClientRectangle, New StringFormat)

'and this line didn't compile

ControlPaint.DrawBorder(e.Graphics, 0, 0, Me.Width, Me.Height)

MyBase.OnPaint(e)

End Sub


Even if this did compile, I don't understand how this is going to paint the
status bar. Can you explain how the status bar knows that it should be
repainted with the blue color?

Thanks!
 
Thanks for that sample project. I didn't pickup the idea that you needed to
put the code into a separate class and use that class the control. I also
didn't realize what I was getting into here. By changing the color like this
I loose the ability to use the panel properties and other properties of the
control which makes it difficult to use. However, I learned something here
and this is good code for reference.

Thanks again.
 
Hi moondaddy,

Yes, after opening the UserPaint style for statusbar, we will lose all the
function of StatusBarPanel, and we have to draw all the things ourselves.

Anyway, I am glad my reply makes sense to you. If you need further help,
please feel free to tell me, I will help you. Thanks!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Actually I do have another question. You answered my question "how to
change the backcolor of the status bar". but because you loose all other
functionality, does anyone actually do this? and if so, why? I think it
would just be easer to build your own status bar out of panels and labels or
something.

Thanks again.
 
Hi moondaddy,

Yes, I am sure that some people really did this, although it needs some
extra work to be done.

For complete sample, please refer to the below article:
"Visual Studio .NET style status bar"
http://www.codeproject.com/cs/miscctrl/ZsDotNetStatusBar.asp

It opens the UserPaint style and do all the things, including painting many
statusbarpanels. You can download its source code, which works well on my
side.
===============================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Ok, I will wait for your further feedback. Thanks!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top