This article will show you a way to display different hints in TStringGrid cells at runtime.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
.
.
.
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure HintHandler(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
.
.
.
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnShowHint := HintHandler;
end;
.
.
.
procedure TForm1.HintHandler(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
var
Poin: TPoint;
Col, Row: Integer;
begin
if HintInfo.HintControl <> StringGrid1 then Exit;
Poin := StringGrid1.ScreenToClient(HintInfo.HintPos);
StringGrid1.MouseToCell(Poin.X, Poin.Y, Col, Row);
HintStr := Format('Hint for col %d and row %d', [Col, Row]);
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
.
.
.
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure HintHandler(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
.
.
.
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnShowHint := HintHandler;
end;
.
.
.
procedure TForm1.HintHandler(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
var
Poin: TPoint;
Col, Row: Integer;
begin
if HintInfo.HintControl <> StringGrid1 then Exit;
Poin := StringGrid1.ScreenToClient(HintInfo.HintPos);
StringGrid1.MouseToCell(Poin.X, Poin.Y, Col, Row);
HintStr := Format('Hint for col %d and row %d', [Col, Row]);
end;
end.
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου