How to display image transition effects on the table.next event (Views: 27)
Problem/Question/Abstract: How to display image transition effects on the table.next event Answer: Here's a rather simple example, using the :DBDEMOS:BIOLIFE table: unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables, ExtCtrls; type TForm1 = class(TForm) Table1: TTable; DataSource1: TDataSource; DBGrid1: TDBGrid; Image1: TImage; Timer1: TTimer; procedure DataSource1DataChange(Sender: TObject; Field: TField); procedure Timer1Timer(Sender: TObject); private { Private declarations } Y: integer; NewBitmap: TBitmap; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} const BIOLifeWidth = 250; BIOLifeHeight = 150; procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField); begin if Table1.State = dsBrowse then begin if NewBitmap = nil then begin NewBitmap := TBitmap.Create; Image1.Picture.Graphic := TBitmap.Create; with TBitmap(Image1.Picture.Graphic) do begin Width := BIOLifeWidth; Height := BIOLifeHeight; end; end; NewBitmap.Assign(Table1.FieldByName('Graphic')); Y := 0; Timer1.Enabled := true; end; end; procedure TForm1.Timer1Timer(Sender: TObject); var R: TRect; begin R := Rect(0, Y, BIOLifeWidth, Y + 4); with TBitmap(Image1.Picture.Graphic) do begin Canvas.CopyRect(R, NewBitmap.Canvas, R); Inc(Y, 4); if Y >= BIOLifeHeight then Timer1.Enabled := false; end; end; end. |