Examples Delphi

Use CM_MOUSEENTER and CM_MOUSELEAVE messages to trap the mouse movements and set a flag.
When painting the component, use this flag like shown here:

class
TMyLabel = class(TLabel)
//..
private
FMouseInPos : Boolean;
procedure CMMouseEnter(var AMsg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var AMsg: TMessage); message CM_MOUSELEAVE;
//.. end;
implementation
procedure TMyLabel.CMMouseEnter(var AMsg: TMessage);
begin
FMouseInPos := True;
Refresh;
end;
procedure TMyLabel.CMMouseLeave(var AMsg: TMessage);
begin
FMouseInPos := False;
Refresh;
end;
// read FMouseInPos when painting the control:
procedure TMyLabel.Paint;
begin
if FMouseInPos then
Font.Color := clBlack
else
Font.Color := clRed; // display an active link in red
inherited;
end;