在TStatusBar上自绘文字或图形,会产生闪烁现象,即使开了双缓冲属性也不行。VCL自带的双缓冲是针对panels的Style为psText时,才管用。但是在psOwnerDraw中频繁画图,经试验仍会闪烁。如,在状态中的某个Panel上显示时间,每秒更新一次,就会闪烁。解决办法是在内存存中绘图,再复制出来,即复制的TStatusBar的Canvas上去。
当然,应该在状态栏的自绘事件中,将上述代码再画一次,这样窗最小化,恢复时系统会自动重绘。
经过测试,不会闪烁。
//---------------------------------------------------------------------------
#include <vcl.h>
#include "gdi.h"
#pragma hdrstop
#include "Unit1.h"
::Graphics::TBitmap * bmp1;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "WinSkinData"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
GdiInit();
bmp1 = new ::Graphics::TBitmap;
bmp1->Width = 1677;
bmp1->Height= 30;
}
void __fastcall TForm1::Timer1Timer(TObject *Sender)//在定时器中画图
{
GdiCreateHandle1(bmp1->Canvas->Handle);
GdiBursh(0,6,bmp1->Width,24,0xffe5e5e5,0xffcccccc,1);
GdiFillRectangle(0,6,727,24);
GdiSetFont("微软雅黑",11);//创建画笔
GdiDrawString(Now(),2,2,0xff000000);
TRect a(753,6,953,24);
TRect b(3,6,203,24);
StatusBar1->Canvas->CopyMode = SRCCOPY;
StatusBar1->Canvas->CopyRect(a,bmp1->Canvas,b);
GdiReleaseGraphics();
}
当然,应该在状态栏的自绘事件中,将上述代码再画一次,这样窗最小化,恢复时系统会自动重绘。
经过测试,不会闪烁。