日期:2014-05-18  浏览次数:20862 次

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

------解决方案--------------------
不容易。up
------解决方案--------------------
给你两个参考示例,研究清楚机制了,自然就明白怎么做了:(附注:都使用到了Win32 API)

http://www.codeproject.com/KB/miscctrl/FileBrowser.aspx

http://www.codeproject.com/KB/tree/TreeViewDragDrop.aspx
------解决方案--------------------
marks
------解决方案--------------------
不容易
------解决方案--------------------
bang ding le
------解决方案--------------------
看看gui怎么实现的,你就明白了
------解决方案--------------------
不是WPF?
------解决方案--------------------
up
------解决方案--------------------
up
------解决方案--------------------
学习中啊,。。
------解决方案--------------------
不容易
------解决方案--------------------
C# code

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

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

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



------解决方案--------------------
很难,学习