C
casey
Unregistered / Unconfirmed
GUEST, unregistred user!
正在编写一动态显示图象的控件,就是可以搞得像屏保程序那种效果的控件,在控件的Paint事件里希望控件的动态效果只显示一次,以后再paint也是直接显示出图象,不再动态显示了。
具体代码如下
var painted:boolean; //一个全局变量
constructor TTransitionImage.Create(AOwner: TComponent);
begin
painted:=false; //初始化为未画过
end;
procedure TTransitionImage.Paint; //这部分参考TImage
var
Save: Boolean;
begin
if (csDesigning in ComponentState) then
begin
with inherited Canvas do
begin
begin
Pen.Style := psDash;
Brush.Style := bsClear;
Rectangle(0, 0, Width, Height);
end;
Save := FDrawing;
FDrawing := True;
try
with inherited Canvas do
StretchDraw(DestRect, FPicture.Graphic); //直接显示
finally
FDrawing := Save;
end
end
else
begin
if not painted then //如果未画过
begin
painted:=true;
Transitions(FTransition) //动态效果
end
else
with inherited Canvas do
StretchDraw(DestRect, FPicture.Graphic); //直接显示
end;
end;
可结果却是在第一次需要动态显示时直接显示了,但是跟踪调试时
第一次显示动态效果那一段却有执行,以后的Paint的确如程序设计那样
到了直接显示这一段,这样的结果让我大惑不解,希望哪个高手可以指点一下。
具体代码如下
var painted:boolean; //一个全局变量
constructor TTransitionImage.Create(AOwner: TComponent);
begin
painted:=false; //初始化为未画过
end;
procedure TTransitionImage.Paint; //这部分参考TImage
var
Save: Boolean;
begin
if (csDesigning in ComponentState) then
begin
with inherited Canvas do
begin
begin
Pen.Style := psDash;
Brush.Style := bsClear;
Rectangle(0, 0, Width, Height);
end;
Save := FDrawing;
FDrawing := True;
try
with inherited Canvas do
StretchDraw(DestRect, FPicture.Graphic); //直接显示
finally
FDrawing := Save;
end
end
else
begin
if not painted then //如果未画过
begin
painted:=true;
Transitions(FTransition) //动态效果
end
else
with inherited Canvas do
StretchDraw(DestRect, FPicture.Graphic); //直接显示
end;
end;
可结果却是在第一次需要动态显示时直接显示了,但是跟踪调试时
第一次显示动态效果那一段却有执行,以后的Paint的确如程序设计那样
到了直接显示这一段,这样的结果让我大惑不解,希望哪个高手可以指点一下。