由于鼠标位置一般是在鼠标移动事件中获得,可以用迂回的办法,类似如下:
public partial class Form1 : Form
{
//用全局变量中转
Point mouseLocation;
public Form1()
{
InitializeComponent();
}
//在鼠标移动事件中实时更新全局变量
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
this.mouseLocation = e.Location;
}
//鼠标点击事件中显示此变量
private void Form1_Click(object sender, EventArgs e)
{
this.Text = this.mouseLocation.ToString();
}
}