我需要实现一个鼠标垫拖拽功能需要先在mousedown的时候记录鼠标的位置
在mousemove的时候做一个动态效果
再在mouserelease的时候做一个重绘这样一个流程需要分在3个事件里比较麻烦
有没有什么比较好的办法可以把这三个事件整合到一起?谢谢

解决方案 »

  1.   

    以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);
            }        
        }
    }
      

  2.   

    不太明白你的意思,你想怎么整合到一起二楼的意思就是在鼠标按下的时候通过API调用,使另外两个事件被调用
      

  3.   

    可能2楼的方法不适合我现在的情况
    我是需要按照顺序触发mouse的down,move,up事件
    这三个事件按顺序执行后可以实现我所需要的功能
    但是这样的话,我就必须将一个功能分拆到三个不同的时间中
    同时这三个事件在其他的情况下还有其他的功能
    这样代码会变得比较凌乱
    我是想有没有什么方法可以将一个多事件的功能整合到一个代码块中完成不知道我说清楚了没
      

  4.   

    因为每个事件里所需要用到的方法不一样啊
    down的时候我要记录鼠标位置
    move的时候我要记录鼠标移动到位置,并且让bitmap跟着鼠标一起动
    up的时候要重绘整个画面关键在于必须按顺序来