C# 移动无边框窗体
来源:互联网 发布:汽车网络宣传方案 编辑:程序博客网 时间:2024/06/08 01:10
private Point mouseOffset;
private bool isMouseDown = false;
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
int xOffset;
int yOffset;
if (e.Button == MouseButtons.Left)
{
xOffset = -e.X /*- SystemInformation.FrameBorderSize.Width*/;
yOffset = -e.Y /*- SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height*/;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
Location = mousePos;
}
}
private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}
另一种
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
private bool isMouseDown = false;
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
int xOffset;
int yOffset;
if (e.Button == MouseButtons.Left)
{
xOffset = -e.X /*- SystemInformation.FrameBorderSize.Width*/;
yOffset = -e.Y /*- SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height*/;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
Location = mousePos;
}
}
private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}
另一种
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
- C# 无边框窗体移动
- C# 移动无边框窗体
- c#移动无边框窗体
- C# 无边框窗体的移动
- 使用C#实现移动无边框窗体
- 使用C#实现移动无边框窗体
- 使用C#实现移动无边框窗体
- C#中无边框窗体移动
- C#无边框窗体的移动
- c# 移动拖动无边框窗体
- C#无边框窗体的移动
- C#中无边框窗体移动
- c# winform移动无边框窗体
- c# 移动拖动无边框窗体
- C#无边框控制窗体移动
- 无边框窗体移动
- c#窗体移动(无边框移动/用户区移动)
- C#去边框以及无边框窗体移动
- css3过渡
- 大话存储系列14——集群文件系统
- Objective C 中 BOOL与bool
- C++ map的基本操作和使用
- git 和svn的对比
- C# 移动无边框窗体
- C#解析JSON的几种方法
- 风华游戏创始人:我的创业失败经验
- OpenCV(2.4.4及之前版本)polyfit函数存在潜在的bug
- OMAPL138/AM1808支持NAND及其ECC出现的问题回复
- sql中得到刚刚插入的数据的id
- blobtrack改成摄像头输入
- static和extern的区别
- 求本月有几天