2011-10-14 3 views
2

내 자신의 DBGrid에 열 제목 힌트를 구현한다고 생각했습니다. 그것은 단순한 것 같습니다 - 나는 생각했다.Delphi : DBGrid 열 제목 힌트 - 힌트를 다시 설정 하시겠습니까?

제가

TitleHints 덧붙여 TStrings를을

이 포맷 정보를 포함

:

이름 = 값 이름 비 필드 기반 열의 (0-99)이다

필드 기반 열의 필드 이름. 값은 열의 힌트이며, crlf는 \ n입니다.

모두 괜찮습니다. OnMouseMove는 위치 기반 힌트입니다.

하지만 첫 번째 힌트 만 표시되며 다음은 표시되지 않습니다. 힌트 메커니즘이 "컨트롤"에 도착한 마우스에서 활성화 되었기 때문에 이것이라고 생각합니다 ... 컨트롤을 종료하고 다시 올 때 다른 힌트를 얻습니다 - 한 번. 상관없이 ShowHint를 off로 설정합니다.

가능한 경우 내 자신의 HintWIndow를 만들고 싶지 않기 때문에 Hint 메커니즘을 Applicaion으로 재설정하는 방법을 찾습니다.이 컨트롤은이 컨트롤의 첫 번째 사례입니다. "메시지 보내기"와 같은 방법으로 전화를 걸거나 "취소 힌트"를 부를 수 있습니다.

이 방법에 대해 알고 계십니까?

도움을 주셔서 감사합니다. 좋은 하루 되세요.

감사합니다 : DD

답변

3

당신은 예를 들어, MouseMove 오버라이드 (override)에서 힌트를 활성화 할 수 있습니다 :

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 속성에서 올바른 값을 반환하도록 구현해야합니다 .

희망이 도움이됩니다.