c# 如何按住一个控件时,可以利用这个控件移动窗体位置
�0�2�0�2源代码,已测试privatePointmouse_offset;privatevoidbutton...
�0�2 �0�2源代码,已测试
private Point mouse_offset;
private void button1_MouseDown(object sender, MouseEventArgs e)
{
mouse_offset = new Point(-e.X, -e.Y);
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouse_offset.X, mouse_offset.Y);//设置偏移
this.button1.Location = this.PointToClient(mousePos);
}
}
�0�2这是您回答的答案 , 请您能否详细说下每一步的原因呢 ?�0�2或许大致说下每一步的意思 ,由于我是新手 , 所以麻烦您了 。�0�2谢谢 。 展开
private Point mouse_offset;
private void button1_MouseDown(object sender, MouseEventArgs e)
{
mouse_offset = new Point(-e.X, -e.Y);
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouse_offset.X, mouse_offset.Y);//设置偏移
this.button1.Location = this.PointToClient(mousePos);
}
}
�0�2这是您回答的答案 , 请您能否详细说下每一步的原因呢 ?�0�2或许大致说下每一步的意思 ,由于我是新手 , 所以麻烦您了 。�0�2谢谢 。 展开
1个回答
2013-09-21
展开全部
private Point mouse_offset; //记录位置
private void button1_MouseDown(object sender, MouseEventArgs e)
{
mouse_offset = new Point(-e.X, -e.Y);
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) //如果是左击鼠标
{
Point mousePos = Control.MousePosition; //获取鼠标的位置
mousePos.Offset(mouse_offset.X, mouse_offset.Y);//设置偏移
this.button1.Location = this.PointToClient(mousePos);
}
}
private void button1_MouseDown(object sender, MouseEventArgs e)
{
mouse_offset = new Point(-e.X, -e.Y);
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) //如果是左击鼠标
{
Point mousePos = Control.MousePosition; //获取鼠标的位置
mousePos.Offset(mouse_offset.X, mouse_offset.Y);//设置偏移
this.button1.Location = this.PointToClient(mousePos);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询