【问题标题】:Delphi: DBGrid Column Title Hint - force to reset the hint?Delphi:DBGrid 列标题提示 - 强制重置提示?
【发布时间】:2011-12-07 12:28:20
【问题描述】:

我认为我在自己的 DBGrid 中实现了列标题提示。 这似乎很简单 - 我想。

我加了

TitleHints : TStrings

包含这种格式的信息:

名称=值

其中 name 是 (0-99) 用于非基于字段的列,fieldname 用于基于字段的列。 值为该列的Hint,crlf为\n。

一切正常,OnMouseMove 是基于位置的提示。

但是:只显示第一个提示,下一个不显示。 我认为这是因为提示机制在鼠标到达“控制”时被激活......当我离开控制并再次出现时,我得到另一个提示 - 一次。 不管我是否将 ShowHint 设置为关闭。

因为如果可能的话我不想创建自己的 HintWIndow,所以我寻找一种方法将 Hint 机制重置为 Applicaion 相信:这是此控件中的第一个案例。 我可以以任何方式执行此操作,例如“发送消息”,或者如果存在则调用“取消提示”等。

你知道这种方式吗?

感谢您的帮助,祝您有美好的一天!

问候: dd

【问题讨论】:

    标签: delphi controls title dbgrid hint


    【解决方案1】:

    您可以在覆盖的MouseMove 中重新激活提示,例如:

    type
      TDBGrid = class(DBGrids.TDBGrid)
      private
        FLastHintColumn: Integer;
      protected
        procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
        function GetColumnTitleHint(Col: Integer): string;
        procedure MouseMove(Shift: TShiftState; X: Integer; Y: Integer); override;
      public
        constructor Create(AOwner: TComponent); override;
      end;
    
    
    procedure TDBGrid.CMHintShow(var Message: TCMHintShow);
    var
      Cell: TGridCoord;
    begin
      if not Assigned(Message.HintInfo) or not (dgTitles in Options) then
        inherited
      else
      begin
        Cell := MouseCoord(Message.HintInfo^.CursorPos.X, Message.HintInfo^.CursorPos.Y);
        if Cell.Y = 0 then
        begin
          FLastHintColumn := Cell.X - 1;
          Message.HintInfo^.HintStr := GetColumnTitleHint(FLastHintColumn);
        end
        else
          FLastHintColumn := -1;
      end;
    end;
    
    function TDBGrid.GetColumnTitleHint(Col: Integer): string;
    begin
      Result := Columns[Col].Title.Caption + ' hint';
    end;
    
    procedure TDBGrid.MouseMove(Shift: TShiftState; X, Y: Integer);
    var
      Cell: TGridCoord;
    begin
      inherited MouseMove(Shift, X, Y);
      if dgTitles in Options then
      begin
        Cell := MouseCoord(X, Y);
        if Cell.Y = 0 then
        begin
          if Cell.X - 1 <> FLastHintColumn then
            Application.ActivateHint(Mouse.CursorPos);
        end
        else
          Application.CancelHint;
      end;
    end;
    
    constructor TDBGrid.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      FLastHintColumn := -1;
    end;
    

    GetColumnTitleHint 只是一个示例,您应该实现它以从您的TitleHints 属性返回正确的值。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2018-12-25
      • 1970-01-01
      • 2013-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-05
      • 1970-01-01
      相关资源
      最近更新 更多