当去掉WinForm的边框时候,鼠标移动窗口的方法
来源:互联网 发布:网络音柱 编辑:程序博客网 时间:2024/05/16 00:42
【方法一】窗体本身进行
#region 鼠标移动窗口
// 位置 - 用于记录鼠标位置Point downPoint;
// 当鼠标按下时,记录鼠标位置
private void MainForm_MouseDown(object sender, MouseEventArgs e)
{
//Point FrmP = new Point(button1.Left, button1.Top);
////ScreenP返回相对屏幕的坐标 Point ScreenP=this.PointToScreen(FrmP);
downPoint = new Point(e.X, e.Y);
}
// 当鼠标移动是,改变窗体位置
private void MainForm_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
Location = new Point(Location.X + e.X - downPoint.X, Location.Y + e.Y - downPoint.Y);
}
#endregion
【方法二】在窗体控件上进行
#region //鼠标坐标private int xpos;
private int ypos;
#region panel1在表面,鼠标移动窗体
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
xpos = e.X;
ypos = e.Y;
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Left += e.X - this.xpos;
this.Top += e.Y - this.ypos;
}
}
#endregion
【方法三】转载于博客园<小锋刚>
窗体的移动:
bool formMove = false;//窗体是否移动
Point formPoint;//记录窗体的位置
private void Form4_MouseDown(object sender, MouseEventArgs e)//鼠标按下
{
formPoint = new Point();
int xOffset;
int yOffset;
if (e.Button == MouseButtons.Left)
{
xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
formPoint = new Point(xOffset, yOffset);
formMove = true;//开始移动
}
}
private void Form4_MouseMove(object sender, MouseEventArgs e)//鼠标移动
{
if (formMove == true)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(formPoint.X, formPoint.Y);
Location = mousePos;
}
}
private void Form4_MouseUp(object sender, MouseEventArgs e)//鼠标松开
{
if (e.Button == MouseButtons.Left)//按下的是鼠标左键
{
formMove = false;//停止移动
}
}
{
if (e.Button == MouseButtons.Left)
{
this.Left += e.X - this.xpos;
this.Top += e.Y - this.ypos;
}
}
#endregion
【案例】
拖动无边框窗体Form至桌面任何位置
首先建一个Windows应用程序
将Form1的 FormBorderStyle属性设置为None
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;
}
}
- 当去掉WinForm的边框时候,鼠标移动窗口的方法
- 鼠标移动没有标题栏的winform窗口
- WinForm窗体没有系统边框的时候移动窗体
- winform技巧—没有边框移动窗体的方法
- Qt无边框窗口的移动、拉伸边框、鼠标滚轮缩放大小
- 去掉鼠标点击后的虚线边框
- 最好的移动无边框窗口的方法
- Winfrom窗体在去掉窗体边框的情况下使鼠标移动窗体
- UIWebView 去掉边框的方法
- 去掉AlertDialog边框的方法
- 鼠标经过时候边框的实现
- 在MFC中,想要实现当鼠标移动到某个标签中的时候鼠标变成超链接时候的“手”状
- WinForm之无边框窗体的移动
- C# 鼠标拖动WinForm无边框窗口
- c# 鼠标移动带边框的pictureBox
- chrome浏览器当鼠标碰到超链接的时候会窗口会抖动
- 1、当鼠标移动到目标上的时候,自动显示一个提示框。
- java中怎样实现当鼠标移动到按钮的时候有提示文字出现
- CSS3 Transition
- 同一个tomcat 多个端口 对应多个应用
- Intent Action
- 2013个人回顾及总结(2)
- 新生命降临
- 当去掉WinForm的边框时候,鼠标移动窗口的方法
- linux下openldap 服务器数据导入(crl)
- 今天想当然地被scala小坑了一下,Source的getLines回返的是Iterator我想当然地以为是list.
- sybase_监控和分析(完善中)
- CSS3 Transform
- highcharts 带上下限的曲线图
- 利用辗转相除法求两个整数的最大公约数和最小公倍数。
- smarty完成指定年份的输出
- const的用法-很详细