请,我需要帮助帆布用途: 当用户在DBGrid中的标题栏移动鼠标, 标题描述德尔福XE 3. 这个问题会消失在Delphi 7使用Canvas.TextOut在DBGrid中 - 德尔福XE 3
不occurr按照下面的代码:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Graphics, Controls, Forms, Dialogs, Data.DB, Datasnap.DBClient,
Grids, DBGrids, Types, StdCtrls;
type
TAccessDBGrid = class(TCustomGrid);
type
TForm1 = class(TForm)
DataSource1: TDataSource;
grid1: TDBGrid;
cdsTabela: TClientDataSet;
cdsTabelacodigo_1: TIntegerField;
cdsTabelacodigo_2: TIntegerField;`enter code here`
procedure grid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure grid1TitleClick(Column: TColumn);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
cdsTabela.CreateDataSet;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
grid1.Refresh;
end;
procedure TForm1.grid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
S1 : string;
begin
with TAccessDBGrid(grid1) do
begin
RowHeights[0] := 29;
Canvas.Brush.Color := clBtnFace;
case Column.Index of
0:
begin
Column.Title.Caption := '';
S1 := 'Code';
end;
1:
begin
Column.Title.Caption := '';
S1 := 'Description';
end;
end;
TDBGrid(Sender).Canvas.Font.Color:= clBlack;
Canvas.TextOut(Rect.Left + 3, 19, S1);
end;
end;
procedure TForm1.grid1TitleClick(Column: TColumn);
begin
ShowMessage('Title Click! ');
end;
end
欲了解更多信息,请参阅我已经发布了答案。
你怎么能指望改变行高后,你已经开始画行是去工作?我没有这台机器上的D7,但我不认为它在那里工作。改为在FormCreate事件中设置该行的高度。为什么你在调用'Canvas.TextOut'时对'19'进行硬编码,而不是使用'Rect.Top'中的偏移量?当你改变而不是使用'19'时会发生什么?你的代码没有意义;您将删除每一行上的Title.Caption,并在每行的每个单元格中从S1中绘制相同的文本。此代码从未工作。 –
@KenWhite:你说“这段代码从来没有工作过”是完全正确的。它在我的D7中肯定无法正常工作。 – MartynA