The TControl class introduces a new property, CustomHint, along with its parent property, ParentCustomHint, which lets child objects share the value defined by the parent control:
property CustomHint: TCustomHint read GetCustomHint write SetCustomHint; property ParentCustomHint: Boolean read FParentCustomHint write SetParentCustomHint default True;
This new property let's you hook a custom hint object to any visual component, that is an object of any class inheriting from TCustomHint. One such class, introduced in Delphi 2009, is the TBalloonHint class, a very simple
113 Vista support in the VCL is covered in detail in my "Delphi 2007 Handbook". Marco Cantu, Delphi 2009 Handbook component that adds very little to what the base TCustomHint class already provides. The custom hint architecture, though, is more flexible than having only balloon hint support, as you can add your own custom hint classes and use them for any control.
What you can use out-of-the-box is a BalloonHint component. Simply place this non-visual component on a form and hook it to the CustomHint property of a control to change the way the hint is displayed. You can see a BalloonHint component below:
Here are the related settings from the DFM file of the HintsDemo example:
object btnCustomHint: TButton
Hint = 'This is a hint for the button' CustomHint = BalloonHintl ShowHint = True end object BalloonHintl: TBalloonHint
Images = ImageListl end
The BalloonHint component uses the hint provided by the control on to which it is hooked. As a user moves the mouse over the button, the hint will be displayed in a much nicer way than in the past:
Using the ParentShowHint and ParentCustomHint properties you can define this setting on a panel and have balloon hints active on each of the controls hosted by the panel. For an example, you can see the Panell control of the HintsDemo project.
You might have noticed in the DFM listing above that the BalloonHint component has an Images property, but no image is displayed. One way to set other runtime properties of the BalloonHint component, including the Title and the Imagelndex, and have a nicer looking hint, is to manually invoke the hint, for example from the OnMouseEnter event of a control:
procedure TForm30.btnShowHintMouseEnter(Sender: TObject); begi n
BalloonHintl.Title := 'Hint Title';
-This is a hint for the button]
BalloonHintl.Imagelndex := 1; BalloonHintl.Description :=
'This is a hint suggesting what a user would do'; BalloonHintl.HideAfter := 5000; BalloonHintl.ShowHint; end ;
procedure TForm30.btnShowHintMouseLeave(Sender: TObject); begi n
BalloonHintl.HideHint; end ;
The hint, visible in the image below, will hide after 5 seconds or as soon as the mouse leaves the control:
As this would require a lot of work, there is another easier way to set the title and the image index of the custom hint object connected with a control. Since the early days of Delphi, the Hint property allowed you to specify a short hint (used as hint) and a longer version (generally for a StatusBar message) separated by the pipe character (|). Using the custom hint association, the Hint property is now interpreted as follows: | title|message|imageindex
So for example, in the HintsDemo project I've customized a button as follows (the value of the hint is a single string):
Was this article helpful?
What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.