以button为例using System; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsApplication2 { public partial class Form1 : Form { [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; public Form1() { InitializeComponent(); } private void button1_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.button1.Handle.ToInt32(), WM_SysCommand, SC_MOVE, 0); } } }
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
[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; public Form1()
{
InitializeComponent();
} private void button1_MouseDown(object sender, MouseEventArgs e)
{ ReleaseCapture();
SendMessage(this.button1.Handle.ToInt32(), WM_SysCommand, SC_MOVE, 0);
}
}
}
我是需要按照顺序触发mouse的down,move,up事件
这三个事件按顺序执行后可以实现我所需要的功能
但是这样的话,我就必须将一个功能分拆到三个不同的时间中
同时这三个事件在其他的情况下还有其他的功能
这样代码会变得比较凌乱
我是想有没有什么方法可以将一个多事件的功能整合到一个代码块中完成不知道我说清楚了没
down的时候我要记录鼠标位置
move的时候我要记录鼠标移动到位置,并且让bitmap跟着鼠标一起动
up的时候要重绘整个画面关键在于必须按顺序来