码迷,mamicode.com
首页 > 其他好文 > 详细

为控件创建MouseEnter和MouseLeave事件(覆盖WndProc,增加对消息的处理)——真简单!

时间:2016-03-23 06:33:00      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

其实很简单:

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=

为控件创建MouseEnter和MouseLeave事件(覆盖WndProc,增加对消息的处理)——真简单!

标签:

原文地址:http://www.cnblogs.com/findumars/p/5309515.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!