新手提问 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 那么当我按下去的时候窗口便会自动消失,这是怎么回事呢? 展开
启帆信息
2024-11-19 广告
2024-11-19 广告
启帆信息是英伟达中国区代理商,原厂授权代理,提供全面的软件技术解决方案以及NVIDIA以太网产品、交换机等产品,欢迎前来咨询!...
点击进入详情页
本回答由启帆信息提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询