新手提问 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 那么当我按下去的时候窗口便会自动消失,这是怎么回事呢? 展开
微测检测5.10
2023-05-10 广告
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询