定时刷新StatusBar中的panel颜色不起作用
各位:
是否能帮忙看看为何定时刷新StatusBar中的panel颜色不起作用呢?非要有另一个窗口遮住才能刷新它的panel颜色
下面是源码:其中在定时器中会修改StatusIndexFirst、StatusIndexSecond 的值。
void __fastcall TForm1::StatusBar1DrawPanel(TStatusBar *StatusBar, TStatusPanel *Panel,
const TRect &Rect)
{
if(Panel->Index == 0)
{
if(StatusIndexFirst > 0)
{
StatusBar->Canvas->Brush->Color = clRed;
}
else
{
StatusBar->Canvas->Brush->Color = clGreen;
}
StatusBar->Canvas->FillRect(Rect);
StatusBar->Canvas->TextOutA(Rect.Left + 2, Rect.Top + 1, StatusFirst);
}
else if(Panel->Index == 1)
{
if(StatusIndexSecond > 0)
{
StatusBar->Canvas->Brush->Color = clRed;
}
else
{
StatusBar->Canvas->Brush->Color = clGreen;
}
StatusBar->Canvas->FillRect(Rect);
StatusBar->Canvas->TextOutA(Rect.Left + 2, Rect.Top + 1, StatusSecond);
}
}
[解决办法]
定时器中修改StatusIndexFirst、StatusIndexSecond 的值并不会触发StatusBar的重绘事件。
建议在定时器的代码中,修改了 StatusIndexFirst、StatusIndexSecond 的值以后再加一句:
StatusBar1->Invalidate();