日期:2010-01-13  浏览次数:20579 次

测试准备, 在空白窗体上添加 Memo1 和 Button1, 然后激活 Form1 的如下事件(巅枫同学关心的):

  OnMouseEnter、OnMouseLeave、OnMouseWheel、OnMouseWheelDown、OnMouseWheelUp, 还用到其 OnCreate 事件.

  然后根据如下测试代码, 一试便知:

 unit Unit1; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls; 
 
type 
  TForm1 = class(TForm) 
    Memo1: TMemo; 
    Button1: TButton; 
    procedure FormCreate(Sender: TObject); 
    procedure FormMouseEnter(Sender: TObject); 
    procedure FormMouseLeave(Sender: TObject); 
    procedure FormMouseWheel(Sender: TObject; Shift: TShiftState; 
      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); 
    procedure FormMouseWheelDown(Sender: TObject; Shift: TShiftState; 
      MousePos: TPoint; var Handled: Boolean); 
    procedure FormMouseWheelUp(Sender: TObject; Shift: TShiftState; 
      MousePos: TPoint; var Handled: Boolean); 
  end; 
 
var 
  Form1: TForm1; 
 
implementation 
 
{$R *.dfm} 
 
procedure TForm1.FormCreate(Sender: TObject); 
begin 
  Memo1.ScrollBars := ssBoth; 
  Self.AutoScroll := True; 
end; 
 
procedure TForm1.FormMouseEnter(Sender: TObject); 
begin 
  Memo1.Lines.Add('Form1_OnMouseEnter'); 
end; 
 
procedure TForm1.FormMouseLeave(Sender: TObject); 
begin 
  Memo1.Lines.Add('Form1_OnMouseLeave'); 
end; 
 
procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState; 
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); 
begin 
  Memo1.Lines.Add('Form1_OnMouseWheel'); 
end; 
 
procedure TForm1.FormMouseWheelDown(Sender: TObject; Shift: TShiftState; 
  MousePos: TPoint; var Handled: Boolean); 
begin 
  Memo1.Lines.Add('Form1_OnMouseWheelDown'); 
  Button1.Top := Button1.Top - 4; 
end; 
 
procedure TForm1.FormMouseWheelUp(Sender: TObject; Shift: TShiftState; 
  MousePos: TPoint; var Handled: Boolean); 
begin 
  Memo1.Lines.Add('Form1_OnMouseWheelUp'); 
  Button1.Top := Button1.Top + 4; 
end; 
 
end.