Author: Tomas Rutkauskas
How to display hints on the title bar of a TForm
Answer:
To accomplish this you need to create a handler for the OnHint event for
TApplication. Whenever a hint is going to fire, Delphi calls the
TApplication.OnHint event for processing, if nothing is defined then the default
processing occurs (i.e. the yellow tool-tip window).
To override the event, you need to define a TNotifyEvent method in your form and
assign it to Application.OnHint. Following is sample code that demonstrates this.
To use, create a new project and drop three buttons on the form. Then set the
Form's ShowHint property to True. Finally enter the following code and run the
application, when you move the mouse over the buttons, their hint will appear as
the form's caption.
1 unit Sample1;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 StdCtrls;
8
9 type
10 TForm1 = class(TForm)
11 Button1: TButton;
12 Button2: TButton;
13 Button3: TButton;
14 procedure FormCreate(Sender: TObject);
15 private
16 { Private declarations }
17 public
18 procedure DoHint(Sender: TObject);
19 end;
20
21 var
22 Form1: TForm1;
23
24 implementation
25
26 procedure TForm1.DoHint(Sender: TObject);
27 begin
28
29 {A hint can contain to pieces, a short and long hint separated by a pipe '|'
30 (e.g. "Open File|Displays a file browser to select file to open". The short hint is
31 "Open File" and the long hint is "Displays a file browser to select file to open".)
32
33 To display the short portion, use the global method
34 GetShortHint(const Hint: string): string;
35
36 To display the long portion, use the global method
37 GetLongHint(const Hint: string): string;}
38
39 Caption := GetLongHint(Application.Hint);
40 end;
41
42 procedure TForm1.FormCreate(Sender: TObject);
43 begin
44 Application.OnHint := DoHint;
45 {Assigns the form's current caption as the form's hint}
46 Hint := Caption;
47 {Assign Hints to the buttons}
48 Button1.Hint := 'Button One|This is the hint for button 1';
49 Button2.Hint := 'Button Two|This is the hint for button 2';
50 Button3.Hint := 'Button Three|This is the hint for button 3';
51 end;
52
53 end.
|