新手提问 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个回答
网易云信
2023-12-06 广告
2023-12-06 广告
UIkit是一套轻量级、模块化且易于使用的开源UI组件库,由YOOtheme团队开发。它提供了丰富的界面元素,包括按钮、表单、表格、对话框、滑块、下拉菜单、选项卡等等,适用于各种类型的网站和应用程序。UIkit还支持响应式设计,可以根据不同...
点击进入详情页
本回答由网易云信提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询