怎么样才能用C#实现像Windows那样的拖动效果呀?
现在窗口内的拖动功能已经实现,主要是半透明图标如何跟随鼠标移动跨窗口拖动(就跟Windows中从一个文件夹拖动到另一个文件夹或桌面上一样)
就像在Windows中选中一个或多个文件拖动时有半透明的图标跟随鼠标移动,松开鼠标时把拖着的东西放到松开时的位置。如在我的项目中有两个窗口,窗口A中有一个image,如何能把它拖动到窗口B中,并且拖动时有半透明图标跟随鼠标的效果,当然在此处是image跟随鼠标

解决方案 »

  1.   

    给你两个参考示例,研究清楚机制了,自然就明白怎么做了:(附注:都使用到了Win32 API)http://www.codeproject.com/KB/miscctrl/FileBrowser.aspxhttp://www.codeproject.com/KB/tree/TreeViewDragDrop.aspx
      

  2.   

    看看gui怎么实现的,你就明白了
      

  3.   


    private const int SC_MOVE = 0xF012;
    private const int WM_SysCommand = 0x0112;
    [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SendMessage")]
    private static extern int SendMessage(int hWnd, int wMsg, int wParam, int lParam);
    [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "ReleaseCapture")]
    private static extern int ReleaseCapture();
    if (WindowState == FormWindowState.Normal)
    {
      ReleaseCapture();
      SendMessage(this.Handle.ToInt32(), WM_SysCommand, SC_MOVE, 0);
    }
    这个不知道行不行呢~~
      

  4.   

    上面那个是移动窗体的,如果想移动控件,可以指定控件的Handle.
    下面是移动一个按钮.
    private void button1_MouseDown(object sender, MouseEventArgs e)
            {
                ReleaseCapture();
                SendMessage(this.button1.Handle.ToInt32(), WM_SysCommand, SC_MOVE, 0);        }
      

  5.   

    你是说跨窗口拖图片是吧?
    其实简单,你拖过去的是一个图片地址,那边接收的也是一个图片地址,于是用这个创建一个新的image,
    放在新的图片框中就行了。
    这个似乎我做过0 0。。
      

  6.   

    是winform程序,拖的东西不仅限于图片
      

  7.   

    csdn 的论坛就是垃圾,问题经典, 回复帖子多半是废帖.