C#使用_鼠标拖动无标题栏窗口
2008-12-08 20:43
351 查看
今天晚上在论坛看到牛人回复了,受教不少
用鼠标控制无标题栏Form的移动,以前只知道通过注册MouseDown,MouseMove和MouseUp事件来实现,而使用下面的方法更加简单
来源(http://topic.csdn.net/u/20081208/19/f5d92437-4602-4798-b8d1-0d6730dec98f.html?seed=1470908657)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(int hWnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "ReleaseCapture")]
public static extern int ReleaseCapture();
public const int WM_SysCommand = 0x0112;
public const int SC_MOVE = 0xF012;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle.ToInt32(), WM_SysCommand, SC_MOVE, 0);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
用鼠标控制无标题栏Form的移动,以前只知道通过注册MouseDown,MouseMove和MouseUp事件来实现,而使用下面的方法更加简单
来源(http://topic.csdn.net/u/20081208/19/f5d92437-4602-4798-b8d1-0d6730dec98f.html?seed=1470908657)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(int hWnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "ReleaseCapture")]
public static extern int ReleaseCapture();
public const int WM_SysCommand = 0x0112;
public const int SC_MOVE = 0xF012;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle.ToInt32(), WM_SysCommand, SC_MOVE, 0);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
相关文章推荐
- c# 实现用鼠标拖动没有标题栏的窗口(窗体的任何部分都可实现拖动效果)
- C# 中使用鼠标拖动窗口导致窗口闪动.
- 实现用鼠标拖动没有标题栏的窗口(窗体的任何部分都可实现拖动效果)
- C#窗体隐藏标题栏后,鼠标可拖动窗口的代码!
- c#实现无标题栏窗口的拖动
- C#无标题栏窗体鼠标拖动
- c#:winform鼠标拖动窗口大小时,设定窗口最小尺寸
- 鼠标拖动窗口和拉伸(没有标题栏时)
- C#下如何实现无标题可拖动窗口
- C#下如何实现无标题可拖动窗口
- c#调用API函数拖动无标题窗口及控件
- C#无标题栏窗体鼠标拖动
- c#:winform鼠标拖动窗口大小时,设定窗口最小尺寸
- QT 鼠标拖动无标题窗口
- C#鼠标任意拖动PictureBox等控件(使用API ReleaseCapture SendMessage)
- C#实现Winform鼠标拖动窗口大小时设定窗口最小尺寸的方法
- C#无标题栏窗体鼠标拖动
- c#实现无标题栏窗口的拖动
- dephi中单击鼠标拖动窗口(使用WM_SYSCOMMAND)
- C#无标题栏窗体鼠标拖动