Mouse: How to „HotTrack“ any control

[code lang=“delphi“]// We have to override the WndProc procedure
procedure WndProc(var Message : TMessage); override;

procedure TForm1.WndProc(var Message : TMessage);
begin
// Here we see which component gets changed.
// This bit here tells us which component the mouse is over
if Message.LParam = Longint(Label1) then
ChangeColor(Label1, Message.Msg);
if Message.LParam = Longint(Label2) then
ChangeColor(Label2, Message.Msg);
if Message.LParam = Longint(Label3) then
ChangeColor(Label3, Message.Msg);
if Message.LParam = Longint(CheckBox1) then
ChangeColor(CheckBox1, Message.Msg);
inherited WndProc(Message);
end;

procedure TForm1.ChangeColor(Sender : TObject; Msg : Integer);
Begin
// If a label is the one that the mouse is over then we
// do this
If Sender Is TLabel Then
Begin
if (Msg = CM_MOUSELEAVE) then
(Sender As TLabel).Font.Color := clWindowText;
if (Msg = CM_MOUSEENTER) then
(Sender As TLabel).Font.Color := clBlue;
End;
// If a CheckBox is the one that the mouse is over then we
// do this
If Sender Is TCheckBox Then
Begin
if (Msg = CM_MOUSELEAVE) then
(Sender As TCheckBox).Font.Color := clWindowText;
if (Msg = CM_MOUSEENTER) then
(Sender As TCheckBox).Font.Color := clRed;
End;
End;
[/code]

[tags]Delphi, Misc, Mouse[/tags]

0 Kommentare zu “Mouse: How to „HotTrack“ any control

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.