关于TStatusBar的OnDrawPanel事件解决方案
关于TStatusBar的OnDrawPanel事件
对于TStatusBar的OnDrawPanel事件的执行一直不是很明白!就是它到底是什么时候执行的,通过调试发现当窗体创建时OnDrawPanel事件就已经执行了,难道它不用人为的去调用吗?还有就是它自己自动执行时没有实参怎么执行咧!
我现在想实现这样的一个目的,就是每按下一次按钮状态栏上相关的变量就增加1(因为需要改变字体的颜色,所以用的是OnDrawPanel事件),但现在是按下后,根本值就不变!
------解决方案--------------------
例如你statusbar有3个panle,在属性面板中挨个给它们的style属性设为psOwnerDraw,
或者用代码设置
也可以给只想重绘的panle设置psOwnerDraw,不需要重绘的保持psText
对于TStatusBar的OnDrawPanel事件的执行一直不是很明白!就是它到底是什么时候执行的,通过调试发现当窗体创建时OnDrawPanel事件就已经执行了,难道它不用人为的去调用吗?还有就是它自己自动执行时没有实参怎么执行咧!
我现在想实现这样的一个目的,就是每按下一次按钮状态栏上相关的变量就增加1(因为需要改变字体的颜色,所以用的是OnDrawPanel事件),但现在是按下后,根本值就不变!
procedure TForm1.Button1Click(Sender: TObject);
begin
Inc(DataSourceModuleID);
StatusBar1DrawPanel(StatusBar1,StatusBar1.Panels.Items[0],nRect);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
With nRect Do
begin
left := 0;
top := 218;
right := 0;
bottom := 0;
end;
StatusBar1DrawPanel(StatusBar1,StatusBar1.Panels.Items[0],nRect);
end;
procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
begin
if Panel = StatusBar.Panels.Items[0] Then
begin
StatusBar.Canvas.Font.Color := clBlue;
StatusBar.Canvas.TextRect(Rect,Rect.Left,Rect.Top,'当前模块ID:'+IntToStr(DataSourceModuleID));
end;
end;
------解决方案--------------------
例如你statusbar有3个panle,在属性面板中挨个给它们的style属性设为psOwnerDraw,
或者用代码设置
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
for i := 0 to statusbar1.Panels.Count - 1 do
begin
statusbar1.Panels[i].Style:=psOwnerDraw;
end;
end;
也可以给只想重绘的panle设置psOwnerDraw,不需要重绘的保持psText