gpt4 book ai didi

delphi - 鼠标悬停在单元格上时如何显示 DBGrid.Hint?

转载 作者:行者123 更新时间:2023-12-03 15:48:22 26 4
gpt4 key购买 nike

虽然以下代码确实使用鼠标所在单元格的文本正确设置了 Form1.Caption,但它不会显示任何 DBGrid.Hint 除非我单击该单元格。

这张图有什么问题吗?

type
THackGrid = class(TDBGrid); // to expose protected DataLink property

procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
Cell: TGridCoord;
ActRec: Integer;
begin
Cell := DBGrid1.MouseCoord(X, Y);
if dgIndicator in DBGrid1.Options then
Dec(Cell.X);
if dgTitles in DBGrid1.Options then
Dec(Cell.Y);
if THackGrid(DBGrid1).DataLink.Active and (Cell.X >= 0) and
(Cell.Y >= 0) then
begin
ActRec := THackGrid(DBGrid1).DataLink.ActiveRecord;
try
THackGrid(DBGrid1).DataLink.ActiveRecord := Cell.Y;
Caption := DBGrid1.Columns[Cell.X].Field.AsString; // Form1.Caption shows fine!
DBGrid.Hint := DBGrid1.Columns[Cell.X].Field.AsString; // <== Hint only shows when I click into the cell!
finally
THackGrid(DBGrid1).DataLink.ActiveRecord := ActRec;
end;
end;
end;

最佳答案

使用所需的提示坐标调用 Application.ActivateHint,例如

Procedure ChangeHint(C: TControl; Const Hint: String; p: TPoint);
var
OldHint: String;
begin
OldHint := C.Hint;
if Hint <> OldHint then
begin
C.Hint := Hint;
Application.ActivateHint(p);
end;
end;

procedure TForm3.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
...
ChangeHint(TDBGrid(Sender), YourIntendedHintText, TDBGrid(Sender).ClientToScreen(Point(X, Y)));
....
end;

关于delphi - 鼠标悬停在单元格上时如何显示 DBGrid.Hint?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17700190/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com