现在不少程序,在做窗体的判断时候,获取屏幕坐标~今天Xushine研究院就和大家来分享这个~

public Form1()
{
InitializeComponent();
}
bool beginMove = false;//初始化
int currentXPosition ;
int currentYPosition ;
//鼠标移动事件
private void Form1_MouseMove(object sender,
MouseEventArgs e)
{
if (beginMove)
{
this.Left += MousePosition.X – currentXPosition;

  this.Top += MousePosition.Y – currentYPosition;

  currentXPosition = MousePosition.X;
currentYPosition = MousePosition.Y;
}
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
beginMove = true;
currentXPosition = MousePosition.X;

  currentYPosition = MousePosition.Y;

  }
private void Form1_
MouseUp(object sender, MouseEventArgs e)
{
beginMove = false;//停止移动
}
private void Form1_MouseLeave(object sender, EventArgs e)
{
currentXPosition = 0; //设置初始状态
currentYPosition = 0;
beginMove =
false;
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}

2 对 “C#获取屏幕坐标代码示例”的想法;

评论被关闭。