Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display hint for a disabled control?

Tags:

delphi

I have a check box which will be enabled/disabled at run time. I just want to show different tool tips if it is enabled/disabled. I was thinking about overriding OnMouseEnter event and handle it there but OnMouseEnter will be called only if the control is enabled. How can i possible achieve that behavior? Any help would be appreciated.

I tried to handle OnMouseMove of the form and do something like this

procedure Tdlg.pnlTopMouseMove(Sender: TObject;Shift: TShiftState; X, Y: Integer);
var
  point: TPoint;
  checkBoxCursorPos: TPoint;
begin
  inherited;
  point.X := X;
  point.Y := Y;
  checkBoxCursorPos := chkBx.ScreenToClient(point);
  if (PtInRect(chkBx.ClientRect, checkBoxCursorPos)) then
  begin
    if(chkBx.Enabled) then
      chkBx.Hint := 'Enabled'
    else
      chkBx.Hint := 'Disabled' ;

    Application.ShowHint := True;
  end;

end;

but the condition PtinRect is not satisfied. What i am doing wrong?

like image 757
Jeeva Avatar asked May 14 '13 08:05

Jeeva


2 Answers

There is a simple solution: place an empty TLabel over the checkbox and set its Hint to the value for the disabled checkbox state. The label has to be AutoSize off and you can enforce position and size by its BoundsRect property set to that of the CheckBox.

When the CheckBox is enabled the Hint of the Checkbox is used, while the Hint of the Label is used when the CheckBox is disabled.

Update: just saw that Bummi mentions a similar idea in his comment.

like image 148
Uwe Raabe Avatar answered Sep 29 '22 13:09

Uwe Raabe


The official answer: you can’t.

The workaround: you could try using the form's MouseMove-event (assuming that won’t be disabled, of course), and if the mouse cursor is over the relevant control, display the appropriate hint.

like image 23
Martijn Avatar answered Sep 29 '22 13:09

Martijn