响应mousedown事件,设置控件的position属性

解决方案 »

  1.   

    using System.Runtime.InteropServices;[DllImport("User32.DLL")]
    public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int iParam);
    [DllImport("User32.DLL")]
    public static extern bool ReleaseCapture();
    public const uint WM_SYSCOMMAND = 0x0112;
    public const int SC_MOVE = 61456;
    public const int HTCAPTION = 2;
    private void panel1_MouseDown(object sender, MouseEventArgs e)
    {
        ReleaseCapture();
        SendMessage(Handle, WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0);
    }
      

  2.   

    private void panel1_MouseDown(object sender, MouseEventArgs e)
    {this.Timer_1.Enable =true;
        
    }private void Timer_1_Click()
    {
    在鼠标移动过程中
       用变量记录鼠标某个时刻的坐标,然后与其后一时刻坐标对比,其值该表矢量
    同当前窗体的(Left,Top)变化矢量相等。
    }