Gwena
asked on
Help! My scrolling text is very jerky
I have been trying create a smooth scrolling text effect without
much success :-(
When I used a label the text was both jerky and flickery...
I finally figured out that putting the text onto a panel and
sliding the panel sideways got rid of the flicker...but the jerky
start and stop motion remains. I use the timer to slide the panel
across the form... maybe I need a better timer or a better way to
use the standard one... anybody out there know how to fix this?
..Gwen..
much success :-(
When I used a label the text was both jerky and flickery...
I finally figured out that putting the text onto a panel and
sliding the panel sideways got rid of the flicker...but the jerky
start and stop motion remains. I use the timer to slide the panel
across the form... maybe I need a better timer or a better way to
use the standard one... anybody out there know how to fix this?
..Gwen..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Simonet :-)
Thanx for the info! I will try that code first thing in the morning...I sure hope it works... I am at my wits end trying to get the flickering jerkies out of this scrolling text :)
p.s. I saw that post about your website being plagiarized :-( what a !@#$% that guy is! ..please don't take your site down though...I like your site.
Thanx for the info! I will try that code first thing in the morning...I sure hope it works... I am at my wits end trying to get the flickering jerkies out of this scrolling text :)
p.s. I saw that post about your website being plagiarized :-( what a !@#$% that guy is! ..please don't take your site down though...I like your site.
ASKER
Hi Simonet...
I must be doing something wrong here.. I renamed the code above to marquee.pas
and then installed it as a component in D3
But when I try to use it the panel just remains
blank....I put several strings into the strings list but no text appears.
The events all seem to work OK..
Did I install the component wrong?
I tried installing in D2 but I get an error
"class Tbevel not found" when I try to
put strings into the strings list.
...Gwen..
I must be doing something wrong here.. I renamed the code above to marquee.pas
and then installed it as a component in D3
But when I try to use it the panel just remains
blank....I put several strings into the strings list but no text appears.
The events all seem to work OK..
Did I install the component wrong?
I tried installing in D2 but I get an error
"class Tbevel not found" when I try to
put strings into the strings list.
...Gwen..
It only works in runtime. You don't see any scrolling text in design-time. Besides, you have to call TMarquee.Activate in order to make it work.
Alex
Alex
here ya go:
This code is in a timer event
{// draw bitmap in appropriate position(moving L->R)
BitBlt(bnr.Canvas.Handle,a mt,0,scrll .Width-amt ,bnr.Heigh t,scrll.Ca nvas.Handl e,0,0,SRCC OPY);
BitBlt(bnr.Canvas.Handle,0 ,0,amt,bnr .Height,sc rll.Canvas .Handle,sc rll.Width- amt,0,SRCC OPY);}
// draw bitmap in appropriate position(moving R->L)
BitBlt(bnr.Canvas.Handle,0 ,0,scrll.W idth-amt,b nr.Height, scrll.Canv as.Handle, amt,0,SRCC OPY);
BitBlt(bnr.Canvas.Handle,s crll.width -amt,0,amt ,bnr.Heigh t,scrll.Ca nvas.Handl e,0,0,SRCC OPY);
it scrolls a bitmap, I used it to scroll text by using the textout function. It works okay for me
This code is in a timer event
{// draw bitmap in appropriate position(moving L->R)
BitBlt(bnr.Canvas.Handle,a
BitBlt(bnr.Canvas.Handle,0
// draw bitmap in appropriate position(moving R->L)
BitBlt(bnr.Canvas.Handle,0
BitBlt(bnr.Canvas.Handle,s
it scrolls a bitmap, I used it to scroll text by using the textout function. It works okay for me
oh yeah, a couple other things:
amt is the number of pixels to scroll
and bnr is a label that I used to scroll the text on.
amt is the number of pixels to scroll
and bnr is a label that I used to scroll the text on.
ASKER
Hi Simonet :-)
That marquee effect looks pretty good...
Can it scroll from left to right and right to left
or does it just do up and down ?
I get an error when I stop a program that uses the marquee.. it says 'marquee1 has no parent window' ?
That marquee effect looks pretty good...
Can it scroll from left to right and right to left
or does it just do up and down ?
I get an error when I stop a program that uses the marquee.. it says 'marquee1 has no parent window' ?
ASKER
Hi ckaneta :-)
Your code looks like it might be what I need...
But I'm having trouble getting it to work...
could you please show me an example program
that uses this code... you could put it here or
email it to me at gwena@gurlmail.com
It is always a huge help to me to see working examples of code.... I'm still pretty much a Delphi
newbie.
...Gwen..
Your code looks like it might be what I need...
But I'm having trouble getting it to work...
could you please show me an example program
that uses this code... you could put it here or
email it to me at gwena@gurlmail.com
It is always a huge help to me to see working examples of code.... I'm still pretty much a Delphi
newbie.
...Gwen..
Why are you using BitBlt that copies a part of the bitmap instead of ScrollWindowEx that uses hardware support (if available)?
ScrollWindow is in most of the case the fastest, easiest and flickerfreeest solution (as long you don't use DirectX).
ScrollWindow is in most of the case the fastest, easiest and flickerfreeest solution (as long you don't use DirectX).
Gwena, the component I sent you only does vertical scrolling. I'll see if I can find a horizontal marquee on my library.
Alex
Alex
Here's an example:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, ExtDlgs, Buttons;
type
TForm1 = class(TForm)
Label1: TLabel;
tmr: TTimer;
dir: TRadioGroup;
scroll: TSpeedButton;
lodpic: TSpeedButton;
img1: TImage;
pict: TOpenPictureDialog;
settxt: TSpeedButton;
Edit1: TEdit;
procedure tmrTimer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure lodpicClick(Sender: TObject);
procedure scrollClick(Sender: TObject);
procedure settxtClick(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
scrtxt : String;
pos : Integer;
bmp : TBitmap; //Bitmap to scroll
procedure setscr;
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{------------------------- ---------- ---------- ---------- ---------- ---------- ---}
procedure TForm1.FormCreate(Sender: TObject);
begin
bmp:=TBitmap.Create; pos:=0; scrtxt:='';
pict.InitialDir:=ExtractFi lePath(app lication.e xename);
end;
procedure TForm1.FormActivate(Sender : TObject); begin {} end;
procedure TForm1.FormDestroy(Sender: TObject); begin bmp.Destroy; end;
{------------------------- ---------- ---------- ---------- ---------- ---------- ---}
procedure TForm1.tmrTimer(Sender: TObject);
begin
if dir.ItemIndex = 0 then begin
// draw bitmap in appropriate position(moving L->R)
BitBlt(label1.Canvas.Handl e, pos, 0, bmp.Width-pos, label1.Height,
bmp.Canvas.Handle, 0, 0, SRCCOPY);
BitBlt(label1.Canvas.Handl e, 0, 0, pos, label1.Height, bmp.Canvas.Handle,
bmp.Width-pos, 0, SRCCOPY);
end else if dir.ItemIndex = 1 then begin
// draw bitmap in appropriate position(moving R->L)
BitBlt(label1.Canvas.Handl e, 0, 0, bmp.Width-pos, label1.Height,
bmp.Canvas.Handle, pos, 0, SRCCOPY);
BitBlt(label1.Canvas.Handl e, bmp.width-pos, 0, pos, label1.Height,
bmp.Canvas.Handle, 0, 0, SRCCOPY);
end;
InvalidateRect(label1.canv as.Handle, nil, false );
inc(pos, 5); if (pos >= bmp.width) and (bmp.width<>0) then
pos:=pos mod bmp.width;
end;
procedure TForm1.setscr; // set up bitmap to scroll
var img : TBitmap; ht,w : Integer;
begin
img:=TBitmap.Create; label1.canvas.font:=label1 .font;
if scrtxt = '' then begin
img.LoadFromFile(pict.File Name);
end else begin
ht:=(label1.Height div 2) - (img.Canvas.TextHeight('H' ) div 2);
img.height:=label1.height;
img.width:=8*length(scrtxt )+15;
img.canvas.Brush.color:=cl White; img.canvas.floodfill(1,1,c lBlack,fsS urface);
img.canvas.pen.color:=labe l1.font.co lor;
img.Canvas.TextOut(1,ht,sc rtxt);
end;
bmp.Height:=img.height; bmp.width:=0; w:=img.width;
while bmp.width < label1.width do begin
bmp.width:=bmp.width+img.w idth;
bmp.Canvas.CopyRect(Rect(b mp.width-w , 0, bmp.width, img.height),
img.canvas, Rect(0, 0, img.width, img.height));
end;
img.Destroy;
end;
{------------------------- ---------- ---------- ---------- ---------- ---------- ---}
procedure TForm1.scrollClick(Sender: TObject);
begin
tmr.Enabled:=not(tmr.Enabl ed);
if tmr.Enabled then scroll.caption:='Stop' else scroll.caption:='Start';
end;
procedure TForm1.lodpicClick(Sender: TObject);
begin
pict.FileName:=''; edit1.text:=''; scrtxt:='';
if pict.Execute then begin
img1.Picture.LoadFromFile( pict.FileN ame);
setscr;
end;
end;
procedure TForm1.settxtClick(Sender: TObject);
begin
if edit1.text <> '' then begin
scrtxt := edit1.text;
setscr; pict.FileName:='';
end;
end;
procedure TForm1.Edit1KeyPress(Sende r: TObject; var Key: Char);
begin if key = #13 then settxtClick(Sender); end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, ExtDlgs, Buttons;
type
TForm1 = class(TForm)
Label1: TLabel;
tmr: TTimer;
dir: TRadioGroup;
scroll: TSpeedButton;
lodpic: TSpeedButton;
img1: TImage;
pict: TOpenPictureDialog;
settxt: TSpeedButton;
Edit1: TEdit;
procedure tmrTimer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure lodpicClick(Sender: TObject);
procedure scrollClick(Sender: TObject);
procedure settxtClick(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
scrtxt : String;
pos : Integer;
bmp : TBitmap; //Bitmap to scroll
procedure setscr;
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{-------------------------
procedure TForm1.FormCreate(Sender: TObject);
begin
bmp:=TBitmap.Create; pos:=0; scrtxt:='';
pict.InitialDir:=ExtractFi
end;
procedure TForm1.FormActivate(Sender
procedure TForm1.FormDestroy(Sender:
{-------------------------
procedure TForm1.tmrTimer(Sender: TObject);
begin
if dir.ItemIndex = 0 then begin
// draw bitmap in appropriate position(moving L->R)
BitBlt(label1.Canvas.Handl
bmp.Canvas.Handle, 0, 0, SRCCOPY);
BitBlt(label1.Canvas.Handl
bmp.Width-pos, 0, SRCCOPY);
end else if dir.ItemIndex = 1 then begin
// draw bitmap in appropriate position(moving R->L)
BitBlt(label1.Canvas.Handl
bmp.Canvas.Handle, pos, 0, SRCCOPY);
BitBlt(label1.Canvas.Handl
bmp.Canvas.Handle, 0, 0, SRCCOPY);
end;
InvalidateRect(label1.canv
inc(pos, 5); if (pos >= bmp.width) and (bmp.width<>0) then
pos:=pos mod bmp.width;
end;
procedure TForm1.setscr; // set up bitmap to scroll
var img : TBitmap; ht,w : Integer;
begin
img:=TBitmap.Create; label1.canvas.font:=label1
if scrtxt = '' then begin
img.LoadFromFile(pict.File
end else begin
ht:=(label1.Height div 2) - (img.Canvas.TextHeight('H'
img.height:=label1.height;
img.width:=8*length(scrtxt
img.canvas.Brush.color:=cl
img.canvas.pen.color:=labe
img.Canvas.TextOut(1,ht,sc
end;
bmp.Height:=img.height; bmp.width:=0; w:=img.width;
while bmp.width < label1.width do begin
bmp.width:=bmp.width+img.w
bmp.Canvas.CopyRect(Rect(b
img.canvas, Rect(0, 0, img.width, img.height));
end;
img.Destroy;
end;
{-------------------------
procedure TForm1.scrollClick(Sender:
begin
tmr.Enabled:=not(tmr.Enabl
if tmr.Enabled then scroll.caption:='Stop' else scroll.caption:='Start';
end;
procedure TForm1.lodpicClick(Sender:
begin
pict.FileName:=''; edit1.text:=''; scrtxt:='';
if pict.Execute then begin
img1.Picture.LoadFromFile(
setscr;
end;
end;
procedure TForm1.settxtClick(Sender:
begin
if edit1.text <> '' then begin
scrtxt := edit1.text;
setscr; pict.FileName:='';
end;
end;
procedure TForm1.Edit1KeyPress(Sende
begin if key = #13 then settxtClick(Sender); end;
end.
ASKER
It's not exactly what I was after since it scrolls up/down instead of right/left ... but I found a good use for the code in another project... so I'm going to use it... so here is the 75 points :-)
ASKER
Thanx for the info! I will try that code first thing in the morning...I sure hope it works... I am at my wits end trying to get the flickering jerkies out of this scrolling text :)
p.s. I saw that post about your website being plagiarized :-( what a !@#$% that guy is! ..please don't take your site down though...I like your site.