2010-02-12 41 views

回答

8

这里有一个片段:

Point mouseLocation; 

public Form1() 
{ 
    InitializeComponent(); 

    this.MouseMove += new MouseEventHandler(Form1_MouseMove); 
} 

void Form1_MouseMove(object sender , MouseEventArgs e) 
{ 
    mouseLocation = e.Location; 
} 

@AdriannStander给出了3个研究优秀链接 - 我只是喜欢写代码段;)

0

这一个适用于表单中的所有控件。不只是形式本身!

.... 
InitializeComponent(); 
     foreach (Control ctrl in this.Controls) 
       { 
        ctrl.MouseMove += new MouseEventHandler(globalMouseMove); 
       } 
    .... 

    private void globalMouseMove(object sender, MouseEventArgs e) 
      { 
       //TODO 
      }