unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls;
type
TComboBox =
class(
Vcl.StdCtrls.TComboBox)
private
FcbHintIndex: Integer;
FHintWindow: THintWindow;
protected
procedure Change;
override;
procedure DropDown;
override;
procedure CloseUp;
override;
procedure InitiateAction;
override;
end;
TForm1 =
class(TForm)
cb: TComboBox;
procedure cbChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
protected
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.cbChange(Sender: TObject);
var
P: TPoint;
begin
case (Sender
as TComboBox).ItemIndex
of
0:
(Sender
as TComboBox).Hint := '
null';
1:
(Sender
as TComboBox).Hint := '
eins';
2:
(Sender
as TComboBox).Hint := '
zwei';
3:
(Sender
as TComboBox).Hint := '
drei';
4:
(Sender
as TComboBox).Hint := '
vier';
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
begin
for I := 0
to 4
do
cb.Items.Add(I.ToString);
end;
{ TComboBox }
procedure TComboBox.Change;
var
P: TPoint;
begin
inherited;
if (Hint <> '
')
and DroppedDown
and GetCursorPos(P)
then
FHintWindow.ActivateHint(Rect(P.X + 10, P.Y + 20, P.X + 100, P.Y + 40), Hint);
end;
procedure TComboBox.CloseUp;
begin
inherited;
FHintWindow.Hide;
ControlStyle := ControlStyle - [csActionClient];
end;
procedure TComboBox.DropDown;
begin
inherited;
if not Assigned(FHintWindow)
then
FHintWindow := THintWindow.Create(Self);
FcbHintIndex := -1;
ControlStyle := ControlStyle + [csActionClient];
end;
procedure TComboBox.InitiateAction;
var
Idx: Integer;
begin
inherited;
Idx := ItemIndex;
if Idx <> FcbHintIndex
then
begin
FcbHintIndex := ItemIndex;
Change;
end;
end;
end.