感谢您使用微软产品。在C#中,您可以通过继承System.Windows.Forms.StatusBar控件类,然后重载其BackColor属性和OnPaint(PaintEventArgs pe)事件,来实现修改StatusBar控件对象的背景颜色。至于修改StausBarPanel控件对象的背景颜色,方法类似。下面提供一段示例代码,在继承System.Windows.Forms.StatusBar控件类的基础上,实现定制ColoredStatusBar控件,供您参考:
public class ColoredStatusBar : System.Windows.Forms.StatusBar 
{
private Color m_BackColor  = Color.Bisque; public ColoredStatusBar()
{
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
} public override Color BackColor
{
get { return m_BackColor;}
set 
{
m_BackColor = value;
this.Invalidate();
}
} protected override void OnPaint(PaintEventArgs pe)
{
// TODO: Add custom paint code here
pe.Graphics.FillRectangle(new SolidBrush(this.BackColor),pe.ClipRectangle);
pe.Graphics.DrawString(this.Text,this.Font,new SolidBrush(Color.Red),pe.ClipRectangle.X,pe.ClipRectangle.Y);
if(this.SizingGrip == true)
ControlPaint.DrawSizeGrip(pe.Graphics,this.BackColor,pe.ClipRectangle); // Calling the base class OnPaint
base.OnPaint(pe);
}
}关于StatusBar控件类的更详细信息,请参考MSDN:
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemWindowsFormsStatusBarMembersTopic.htm — 微软全球技术中心 VB支持中心本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。