不要太依靠什么控件了,我已写好单击一个打印按钮而DBGrid的当前行变色的功能。你再配上打印程序就可以了。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids;
type
TForm1 = class(TForm)
dbgrdOne: TDBGrid;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure dbgrdOneDrawColumnCell(Sender: TObject;
const Rect: TRect;
DataCol: Integer;
Column: TColumn;
State: TGridDrawState);
procedure FormCreate(Sender: TObject);
procedure ADOTable1AfterScroll(DataSet: TDataSet);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
G_i: integer;
G_IsPrint: boolean;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
G_IsPrint := true;
dbgrdOne.Repaint;
end;
procedure TForm1.dbgrdOneDrawColumnCell(Sender: TObject;
const Rect: TRect;
DataCol: Integer;
Column: TColumn;
State: TGridDrawState);
begin
if (G_i = dbgrdOne.DataSource.DataSet.RecNo) and
G_IsPrint then
begin
dbgrdOne.Canvas.Brush.Color := clBlue;
//G_IsPrint := false;
dbgrdOne.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end
else
dbgrdOne.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
G_IsPrint := false;
end;
procedure TForm1.ADOTable1AfterScroll(DataSet: TDataSet);
begin
G_i := ADOTable1.RecNo;
end;
end.