新手提问 C# 窗口类中Control.MousePosition属性和 e.positon在实际调用中有什么区别呢?
在网上学习一个按住左键拖动窗口移动的代码。具体有三个函数组成privatevoidfrmTopMost_MouseMove(objectsender,MouseEvent...
在网上学习一个按住左键拖动窗口移动的代码。具体有三个函数组成
private void frmTopMost_MouseMove(object sender, MouseEventArgs e)
{
if(blnMouseDown)
{
// ptMouseNewPos = new Point(e.X, e.Y);
ptMouseNewPos = Control.MousePosition;
ptFormNewPos.X = ptMouseNewPos.X - ptMouseCurrentPos.X + ptFormPos.X;
ptFormNewPos.Y = ptMouseNewPos.Y - ptMouseCurrentPos.Y + ptFormPos.Y;
Location = ptFormNewPos;
ptFormPos = ptFormNewPos;
ptMouseCurrentPos = ptMouseNewPos;
}
}
private void frmTopMost_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
blnMouseDown = true;
// ptMouseCurrentPos = Control.MousePosition; 问题所在!
ptMouseCurrentPos = e.Location;
ptFormPos = Location;
}
}
private void frmTopMost_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
blnMouseDown = false;
}
在mousedown函数中,如果我调用的Control.MousePosition则一切正常,但是如果调用的是e.position 或者 e.X e.Y 那么当我按下去的时候窗口便会自动消失,这是怎么回事呢? 展开
private void frmTopMost_MouseMove(object sender, MouseEventArgs e)
{
if(blnMouseDown)
{
// ptMouseNewPos = new Point(e.X, e.Y);
ptMouseNewPos = Control.MousePosition;
ptFormNewPos.X = ptMouseNewPos.X - ptMouseCurrentPos.X + ptFormPos.X;
ptFormNewPos.Y = ptMouseNewPos.Y - ptMouseCurrentPos.Y + ptFormPos.Y;
Location = ptFormNewPos;
ptFormPos = ptFormNewPos;
ptMouseCurrentPos = ptMouseNewPos;
}
}
private void frmTopMost_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
blnMouseDown = true;
// ptMouseCurrentPos = Control.MousePosition; 问题所在!
ptMouseCurrentPos = e.Location;
ptFormPos = Location;
}
}
private void frmTopMost_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
blnMouseDown = false;
}
在mousedown函数中,如果我调用的Control.MousePosition则一切正常,但是如果调用的是e.position 或者 e.X e.Y 那么当我按下去的时候窗口便会自动消失,这是怎么回事呢? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询