コントロールのMouseEnterとMouseLeaveイベント(WndProcを上書きし、メッセージの処理を増やす)を作成します.簡単ですね.

4683 ワード

実は簡単です.
unit Unit1; 

interface 

uses 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
  StdCtrls; 

type 

  TURLLabel = class(TLabel) 
    procedure WndProc(var Message : TMessage); override; 
  end; 

type 
  TForm1 = class(TForm) 
    procedure FormCreate(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 

var 
  Form1: TForm1; 

implementation 

{$R *.DFM} 

{ TURLLabel } 

procedure TURLLabel.WndProc(var Message: TMessage); 
begin 
  if (Message.Msg = CM_MOUSEENTER) then 
  begin 
    Font.Color := clBlue; 
    Font.Style := Font.Style + [fsUnderline]; 
  end; 
  if (Message.Msg = CM_MOUSELEAVE) then 
  begin 
    Font.Color := clWindowText; 
    Font.Style := Font.Style - [fsUnderline]; 
  end; 
  inherited WndProc(Message); 
end; 

procedure TForm1.FormCreate(Sender: TObject); 
begin 
  with TURLLabel.Create(Self) do 
  begin 
    Parent := Self; 
    Left := 10; 
    Top := 10; 
    caption := 'www.delphi3000.com'; 
    Cursor := crHandPoint; 
  end; 
end; 

end. 

転入先http://www.delphi3000.com/articles/article_1050.asp?SK=