DelphiFAQ Home Search:
General :: Programming :: Delphi :: VCL
About the Delphi VCL (Visual Component Library)

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Only the 40 most recently viewed articles are shown.
You can see the full list here.

Featured Article

Highlight a component when the mouse moves towards 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;
 
 // 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;
You don't like the formatting? Check out SourceCoder then!
Generated 4:01:16 on May 22, 2018