使用剪切或复制从剪贴板粘贴文件 [英] Paste Files from Clipboard with Cut or Copy
本文介绍了使用剪切或复制从剪贴板粘贴文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
.NET Clipboard类具有一些方法,可以将文件放入剪贴板,并定义是否应移动或复制(剪切/复制)文件。
The .NET Clipboard class has methods to put files into the clipboard and also define if they should be moved or copied (cut/copy).
但是如果我想要粘贴文件到剪贴板,我看不出有没有办法使用标准剪贴板方法来剪切或复制文件。
But if I want to paste files that were copied into the clipboard, I see no way to find out if the file was cut or copied with standard Clipboard methods.
推荐答案
该信息存储在一个名为 Preferred DropEffect的剪贴板数据对象中。
包含4字节数组的内存流包含 System.Windows.DragDropEffects
的枚举值:
The information is stored in a Clipboard data object named "Preferred DropEffect".
A memory stream containing a 4-byte-array contains the enum value for System.Windows.DragDropEffects
:
public static void PasteFilesFromClipboard(string aTargetFolder)
{
var aFileDropList = Clipboard.GetFileDropList();
if (aFileDropList == null || aFileDropList.Count == 0) return;
bool aMove = false;
var aDataDropEffect = Clipboard.GetData("Preferred DropEffect");
if (aDataDropEffect != null)
{
MemoryStream aDropEffect = (MemoryStream)aDataDropEffect;
byte[] aMoveEffect = new byte[4];
aDropEffect.Read(aMoveEffect, 0, aMoveEffect.Length);
var aDragDropEffects = (DragDropEffects)BitConverter.ToInt32(aMoveEffect, 0);
aMove = aDragDropEffects.HasFlag(DragDropEffects.Move);
}
foreach (string aFileName in aFileDropList)
{
if (aMove) { } // Move File ...
else { } // Copy File ...
}
}
[Flags]
public enum DragDropEffects
{
Scroll = int.MinValue,
All = -2147483645,
None = 0,
Copy = 1,
Move = 2,
Link = 4
}
这篇关于使用剪切或复制从剪贴板粘贴文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文