How to refresh a BalloonHint that is part of ControlList.CustomHint on MouseOver

Viewed 102

Example without BalloonHint1 works as designed. No issues with the Hint refresh.

procedure TForm1.ControlList1MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
    begin
       ControlList1.ShowHint:=false;
       //ControlList1.CustomHint <-------value is not set as it is not required.
       ControlList1.Hint := IntToStr(ControlList1.HotItemIndex);
       ControlList1.ShowHint:=true;
    end;

When I add a TBalloonHint, the BalloonHint does not display properly.

procedure TForm1.ControlList1MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);

    begin
       ControlList1.ShowHint:=false;
       BalloonHint1.Delay:=0;
       BalloonHint1.HideAfter:=-1;
       ControlList1.CustomHint:=BalloonHint1;
       ControlList1.Hint := IntToStr(ControlList1.HotItemIndex);
       ControlList1.ShowHint:=true;
    end;

When I move my mouse over the ControlList for the first time. A BalloonHint does not show.

If I move my mouse over again (for the 2nd time) then the HotItemIndex from the previous movement shows the index. enter image description here

Is there a way to do a BalloonHint1.Refresh? I have tested some of the following:

Application.CancelHint; ///something that I dont want to do... but i gave it a try

also

ControlList1.ShowHint:=false;
ControlList1.ShowHint:=true;
1 Answers

The following worked.

procedure TForm1.ControlList1MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   BalloonHint1.HideHint;
   BalloonHint1.Delay:=0;
   BalloonHint1.HideAfter:=-1;
   ControlList1.CustomHint:=BalloonHint1;
   ControlList1.Hint := IntToStr(ControlList1.HotItemIndex);
   BalloonHint1.ShowHint(ControlList1);
end;

I then found that the BalloonHint flickered. So I used advice from the following:

Delphi ListView hint flickers

Create a global variable in which I would store reference to last HotItemIndex for which the hint has been shown. Then verify if the current HotItemIndex is the same as the one we stored controlListHotItemIndex.

procedure TForm1.ControlList1MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
 if controlListHotItemIndex<>ControlList1.HotItemIndex then
   begin
     controlListHotItemIndex:=ControlList1.HotItemIndex;
     BalloonHint1.HideHint;
     BalloonHint1.Delay:=0;
     BalloonHint1.HideAfter:=-1;
     ControlList1.CustomHint:=BalloonHint1;
     ControlList1.Hint := IntToStr(ControlList1.HotItemIndex);
     BalloonHint1.ShowHint(ControlList1);
  end;
end;
Related