C#中模仿鼠标拖动窗口
2011-06-23 19:26
260 查看
int x = 0,y=0;//记录鼠标按下时的鼠标所在位置
Boolean flag = false;//标记鼠标是否按下
//添加鼠标移动事件
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (flag == true)
{
//设置窗口的位置
this.Left += e.Location.X - x;
this.Top += e.Location.Y - y;
}
}
//添加鼠标按下事件
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
//记录当前鼠标位置
x = e.Location.X;
y = e.Location.Y;
flag = true;//鼠标按下
}
//添加鼠标放开事件
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
flag = false;//鼠标放开
}
Boolean flag = false;//标记鼠标是否按下
//添加鼠标移动事件
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (flag == true)
{
//设置窗口的位置
this.Left += e.Location.X - x;
this.Top += e.Location.Y - y;
}
}
//添加鼠标按下事件
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
//记录当前鼠标位置
x = e.Location.X;
y = e.Location.Y;
flag = true;//鼠标按下
}
//添加鼠标放开事件
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
flag = false;//鼠标放开
}
相关文章推荐
- c# 鼠标在控件上拖动 移动窗体 移动窗口
- C#使用_鼠标拖动无标题栏窗口
- c# 实现用鼠标拖动没有标题栏的窗口(窗体的任何部分都可实现拖动效果)
- C#实现Winform鼠标拖动窗口大小时设定窗口最小尺寸的方法
- C#窗体隐藏标题栏后,鼠标可拖动窗口的代码!
- c#:winform鼠标拖动窗口大小时,设定窗口最小尺寸
- c#:winform鼠标拖动窗口大小时,设定窗口最小尺寸
- C# 中使用鼠标拖动窗口导致窗口闪动.
- C#实现鼠标拖动自定义窗口
- C# Winform 让整个窗口都可以拖动
- c# 鼠标拖动缩放图片
- C#基础系列:开发自己的窗体设计器(在容器上拖动鼠标增加控件)
- C# 实现无标题栏窗口拖动效果
- C#无标题栏窗体鼠标拖动
- C#鼠标拖动图片picturebox
- C#模拟鼠标键盘控制其他窗口(一)
- MFC-鼠标拖动窗口小到一定程度报错
- C#通过控件拖动窗口
- c# 模仿鼠标拖拽矩形框 张宇轩
- c#实现无标题栏窗口的拖动