Einzelnen Beitrag anzeigen

API

Registriert seit: 18. Apr 2004
637 Beiträge
 
#2

Re: Tooltips per Code aktivieren

  Alt 25. Feb 2008, 19:18
Hallo,

Einen Hint kannst du mit ActivateHint() anzeigen.

Delphi-Quellcode:
  private
    { Private declarations }
    FMyHint: THintWindow;
    function RevealHint(Control: TControl; Color: TColor): THintWindow;
    procedure RemoveHint(var Hint: THintWindow);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// Hint Fenster anzeigen

function TForm1.RevealHint(Control: TControl; Color: TColor): THintWindow;
var
  ShortHint: string;
  AShortHint: array[0..255] of Char;
  HintPos: TPoint;
  HintBox: TRect;
  HeightOfText: Integer;
begin
   { Hint Fenster erstellen falls noch nicht }
  if not Assigned(Result) then
    Result := THintWindow.Create(Control);
  if Color <> 0 then
    Result.Color := Color;
  ShortHint := GetShortHint(Control.Hint);
   { Hint Fenster Position & Größe: }
  HintPos := Control.ClientOrigin;
  Inc(HintPos.Y, Control.Height + 6);
  HintBox := Bounds(0, 0, Screen.Width, 0);
  HeightOfText := DrawText(Result.Canvas.Handle, StrPCopy(PChar(@AShortHint), ShortHint),
    -1, HintBox, DT_CALCRECT or DT_LEFT or DT_WORDBREAK or DT_NOPREFIX);
  OffsetRect(HintBox, HintPos.X, HintPos.Y);
  Inc(HintBox.Right, 6);
  Inc(HintBox.Bottom, 2);
{ Hint zeigen }
  Result.ActivateHint(HintBox, ShortHint);
end;

// Hint verstecken
procedure TForm1.RemoveHint(var Hint: THintWindow);
begin
  if Assigned(Hint) then
  begin
    Hint.ReleaseHandle;
    Hint.Free;
    Hint := nil;
  end;
end;

// Test: Hint von Button2 anzeigen bei Klick auf Button1
procedure TForm1.Button1Click(Sender: TObject);
begin
  FMyHint := RevealHint(Button2, clInfoBk);
  Application.Processmessages;
  Sleep(Application.HintHidePause);
  RemoveHint(FMyHint)
end;
  Mit Zitat antworten Zitat