C# 怎样才能让鼠标按住控件并左右移动控件
///<summary>///定义二维平面的XY///</summary>privatePointMouseXY;privatevoidlblP_MouseDown(ob...
/// <summary>
/// 定义二维平面的XY
/// </summary>
private Point MouseXY;
private void lblP_MouseDown(object sender, MouseEventArgs e)
{
MouseXY = new Point(-e.X,-e.Y);
MessageBox.Show(-e.X+"|********|"+-e.Y);
}
private void lblP_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point p = Control.MousePosition;
p.Offset(MouseXY.X,MouseXY.Y);
if (lblP.Location.Y==-10)
{
Buttons1.Location = this.PointToClient(p);
}
}
}
求教:怎样才能限制该控件的上下移动呢?只要求能左右移动即可,我在线等……谢谢 展开
/// 定义二维平面的XY
/// </summary>
private Point MouseXY;
private void lblP_MouseDown(object sender, MouseEventArgs e)
{
MouseXY = new Point(-e.X,-e.Y);
MessageBox.Show(-e.X+"|********|"+-e.Y);
}
private void lblP_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point p = Control.MousePosition;
p.Offset(MouseXY.X,MouseXY.Y);
if (lblP.Location.Y==-10)
{
Buttons1.Location = this.PointToClient(p);
}
}
}
求教:怎样才能限制该控件的上下移动呢?只要求能左右移动即可,我在线等……谢谢 展开
2个回答
展开全部
改成这样:
p.Offset(MouseXY.X, 0); // y轴方向偏离为0就可以了。
p.Offset(MouseXY.X, 0); // y轴方向偏离为0就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int temp;
private void label1_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button == System.Windows.Forms.MouseButtons.Left )
{
temp = e.X;
}
}
private void label1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
this.label1.Left = e.X - temp + this.label1.Left;
}
}
private void label1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
this.label1.Left = e.X - temp + this.label1.Left;
}
}
这是以一个label为例,其他都一样的啦
private void label1_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button == System.Windows.Forms.MouseButtons.Left )
{
temp = e.X;
}
}
private void label1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
this.label1.Left = e.X - temp + this.label1.Left;
}
}
private void label1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
this.label1.Left = e.X - temp + this.label1.Left;
}
}
这是以一个label为例,其他都一样的啦
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询