Delphi .NET (2) Database (71) Delphi IDE (89) Network (39) Printing (3) Strings (12) VCL (83) Windows with Delphi (280)
Exchange Links About this site Links to us 
|
Highlight a component when the mouse moves towards it
This article has not been rated yet. After reading, feel free to leave comments and rate it.
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;
procedure TMyLabel.Paint;
begin
if FMouseInPos then
Font.Color := clBlack
else
Font.Color := clRed;
inherited;
end; | |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|