Mega Code Archive

 
Categories / Delphi / Examples
 

Sliding text

Title: Sliding text Question: Simple system in order to move a text within a form Answer: unit Move_text; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure Render(Sender: TObject; var Done: Boolean); procedure FormResize(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation var offbmp: TBitmap; Time, xx: Integer; {$R *.DFM} procedure TForm1.Render(Sender: TObject; var Done: Boolean); begin Time := (Time + 1) mod 100; if Time = 0 then begin Inc(xx); Canvas.lock; with OffBmp.Canvas do begin Brush.Color := clYellow; Brush.Style := bsSolid; FillRect(bounds(0, 0, Width, Height)); Font.Name := 'Arial black'; Font.Size := Form1.Height div 8; Font.Color := clRed; Brush.Style := bsClear; TextOut(Form1.Width - xx, 0, 'WWW.Delphiruby.com!'); end; Application.ProcessMessages; Canvas.draw(0, 0, offbmp); // canvas.CopyRect(bounds(0,0,width,height), // offbmp.canvas,bounds(0,0,width,height)); // canvas.bitbl end; Done := False; end; procedure TForm1.FormCreate(Sender: TObject); begin offbmp := TBitmap.Create; offbmp.Width := Form1.Width; offbmp.Height := Form1.Height; with OffBmp do begin Canvas.Brush.Color := clBlack; Canvas.FillRect(bounds(0, 0, Width, Height)); end; Application.OnIdle := render; end; procedure TForm1.FormResize(Sender: TObject); begin offbmp.Width := Form1.Width; offbmp.Height := Form1.Height; with OffBmp do begin Canvas.Brush.Color := clBlack; Canvas.FillRect(bounds(0, 0, Width, Height)); end; end; end.