当鼠标在窗体上滑动时, 可以触发窗体的FormMouseMove方法, 代码如下:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
Label1->Caption = X;
Label2->Caption = Y;
}
//---------------------------------------------------------------------------
但是, 上述方法是有缺陷的, 因为, Label1和Label2在窗体上, 当鼠标滑过他们时候, 窗体被挡住,