一个屏幕不断闪烁的问题

tanweibiao2000 2005-08-23 01:07:53
我要写一个“摇奖”的小软件,按下开始按钮的时候打开一个数据集,并启动Timer。。。。下面这段是写在Timer事件里的:
with qryWzj do
begin
If Eof then
First;
// LockWindowUpdate(frmMain.Handle);
lable.Caption:='姓名: '+FieldByName('姓名').AsString;//Lable 是一个Lable
// Img_back.Canvas.TextOut(1,50,FieldByName('姓名').AsString);//Img_back 是一个Image控件
// LockWindowUpdate(0);
Next;

If Eof then
First;
end;

如果直接用TextOut输出字符串到Img_back上的BMP图上,屏幕会闪得很厉害,如果在Image控件上放一个Lable,那个Lable 会闪得很厉害,屏幕其它地方不闪(Lable 设为透明)。请教怎样解决???
...全文
350 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
cmain83 2005-08-25
  • 打赏
  • 举报
回复
// 给你段代码...
// 决对不闪...


type
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
Bit: TBitMap; // 缓冲区... 记得程序退出时释放
public
{ Public declarations }
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
Self.Bit := TBitMap.Create;
Self.Bit.Width := Self.Image1.Width;
Self.Bit.Height := Self.Image1.Height;
Self.Image1.Visible := False;
Self.Image1.Picture.LoadFromFile('c:\aa.bmp');
Self.Timer1.Interval := 10;
Self.Timer1.Enabled := True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
with Self.Bit do
begin
BitBlt(Canvas.Handle, 0, 0, Width, Height, Self.Image1.Canvas.Handle, 0, 0, SRCCOPY);
Canvas.TextOut(0, 0, 'C.LILAC' + IntToStr(Random($FFFF)));
BitBlt(Self.Canvas.Handle, 0, 0, Width, Height, Canvas.Handle, 0, 0, SRCCOPY);
end;
end;
tanweibiao2000 2005-08-24
  • 打赏
  • 举报
回复
谢谢各位大虾的指导。。。。
派分。。。人人有分。。。
merkey2002 2005-08-23
  • 打赏
  • 举报
回复
Application.ProcessMessages; //加上这句试试
actul 2005-08-23
  • 打赏
  • 举报
回复
同意:xixuemao(俺可是㊣②㈧经儿滴人) ( ) 信誉:100
procedure TForm1.FormCreate(Sender: TObject);
begin
DoubleBuffered:= true;//加上这句试试
end;
See:

Determines whether the control's image is rendered directly to the window or painted to an in-memory bitmap first.

property DoubleBuffered: Boolean;

Description

When DoubleBuffered is False, the windowed control paints itself directly to the window. When DoubleBuffered is True, the windowed control paints itself to an in-memory bitmap that is then used to paint the window. Double buffering reduces the amount of flicker(闪烁) when the control repaints, but is more memory intensive.

When a windowed control is a dock site and has an associated dock manager, it must be double-buffered.

Note: Some controls, such as TRichEdit, can't paint themselves into a bitmap. For such controls, DoubleBuffered must be set to False.
hqhhh 2005-08-23
  • 打赏
  • 举报
回复
with qryWzj do
begin
Application.ProcessMessages; //加上这句试试
If Eof then
First;
lable.Caption:='姓名: '+FieldByName('姓名').AsString;//Lable 是一个Lable
Next;
If Eof then
First;
end;
xixuemao 2005-08-23
  • 打赏
  • 举报
回复
这是个取数据的例子。

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select pbatype from t_pbadefine');
adoquery1.Open;
timer1.Enabled:= true;
timer1.Interval:= 50;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
s: string;
begin
s:= adoquery1.fieldbyname('pbatype').AsString;
label1.Caption:= s;
adoquery1.Next;
end;
xixuemao 2005-08-23
  • 打赏
  • 举报
回复
请问楼主,label闪的很厉害吗?

刚才简单试了一下:

不加LockWindowUpdate情况下,不管是draw在image上还是放一个label,都不闪。

加了LockWindowUpdate出现闪的情况,但很轻微。

楼主可以用下面的测试一下看看:把label放到一个image上,设置为透明。

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
label1.Caption:= '1111111111';
timer1.Enabled:= true;
timer1.Interval:= 100;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
i: integer;
begin
i:= 1;
label1.Caption:= inttostr(strtoint(label1.Caption)+i);
i:= i+1;
end;
tanweibiao2000 2005-08-23
  • 打赏
  • 举报
回复
不是频率问题,就算间隔设成一秒(1000)也是闪。。。。。(我的用意就是让它不断的循环,直到用户按下“停止”按钮或设一个计数器,让计数器达到预期设定值)

xixuemao(俺可是㊣②㈧经儿滴人) 的方法不起作用。。。。
还有没有哪位大虾出来指点一下。。。
Bluce4587 2005-08-23
  • 打赏
  • 举报
回复
在显示过程中,加一句Sleep(100);就行了
konhon 2005-08-23
  • 打赏
  • 举报
回复
Timer的間隔, 你Timer還有一個不停的循環
是不是觸發頻率太大啦.
xixuemao 2005-08-23
  • 打赏
  • 举报
回复
procedure TForm1.FormCreate(Sender: TObject);
begin
DoubleBuffered:= true;//加上这句试试
end;

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧