C#无边框窗体要怎么实现移动?求大神指教!求代码!
如图所示,如何师兄无边框窗体移动?就是控件(不只是picturebox,还有button和panel等等)就在窗体上,随着窗体的移动而移动。最好能有图文教程...
如图所示,如何师兄无边框窗体移动?就是控件(不只是picturebox,还有button和panel等等)就在窗体上,随着窗体的移动而移动。最好能有图文教程
展开
2个回答
推荐于2018-04-11
展开全部
很简单的,将窗体的FormBorderStyle 属性设置为 None,就可以实现无边框了。
给窗体加上 MouseDown 和 MouseMove 事件,然后分别引用下面两个方法
int x, y;
void FormMainMouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
x = e.X;
y = e.Y;
}
}
void FormMainMouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Location = new Point(this.Location.X + (e.X - x), this.Location.Y + (e.Y - y));
}
}
}
展开全部
就是定义窗体的MouseMove、MouseDown和MouseUp事件
Point mouseOff; //鼠标移动位置变量
bool leftFlag;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到变量的值
leftFlag = true; //点击左键按下时标注为true;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;
mouseSet.Offset(mouseOff.X, mouseOff.Y); //设置移动后的位置
Location = mouseSet;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;//释放鼠标后标注为false;
}
}
Point mouseOff; //鼠标移动位置变量
bool leftFlag;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到变量的值
leftFlag = true; //点击左键按下时标注为true;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;
mouseSet.Offset(mouseOff.X, mouseOff.Y); //设置移动后的位置
Location = mouseSet;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;//释放鼠标后标注为false;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询