請,我需要幫助帆布用途: 當用戶在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