剪切文件在C#到剪贴板 [英] Cut files to clipboard in C#

查看:619
本文介绍了剪切文件在C#到剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一种方式来编程下调一档到剪贴板,比如有些调用在C#中的函数,它等同于选择了的 Windows资源管理器和pressing <大骨节病>控制 + <大骨节病> X

I'm looking for a way to programmatically cut a file to the clipboard, for example, some call to a function in C# that does the same as selecting a file in the Windows Explorer and pressing Ctrl + X.

运行程序和pressing后<大骨节病>控制 + <大骨节病> V 在硬盘驱动器上的其他文件夹,原始文件是 感动以新的文件夹。通过查看堆栈溢出问题的 将文件复制到C#中剪贴板 的,我知道这是很容易做到的复印作业,但切割似乎工作不同。我怎样才能做到这一点?

After running the program and pressing Ctrl + V in some other folder on the hard drive, the original file would be moved to the new folder. By looking at Stack Overflow question Copy files to clipboard in C#, I know that it's easy to do the copy job, but cutting seems to work different. How can I do this?

推荐答案

请尝试以下方法,从翻译的的code项目 的文章的设置剪贴板文件DropList与DROPEFFECT在VB.NET 的:

Please try the following, translated from The Code Project article Setting the Clipboard File DropList with DropEffect in VB.NET:

byte[] moveEffect = new byte[] {2, 0, 0, 0};
MemoryStream dropEffect = new MemoryStream();
dropEffect.Write(moveEffect, 0, moveEffect.Length);

DataObject data = new DataObject();
data.SetFileDropList(files);
data.SetData("Preferred DropEffect", dropEffect);

Clipboard.Clear();
Clipboard.SetDataObject(data, true);

这篇关于剪切文件在C#到剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆