wpf 复制/剪切到本地系统剪切板中以供右键粘贴用
/// <summary>
/// 复制或剪切文件到剪切板
/// </summary>
/// <param name="files">文件路径数组</param>
/// <param name="cut">true:剪切;false:复制</param>
public
static
void
CopyToClipboard(
string
[] files,
bool
cut)
{
if
(files ==
null
)
return
;
IDataObject data =
new
DataObject(DataFormats.FileDrop, files);
MemoryStream memo =
new
MemoryStream(4);
byte
[] bytes =
new
byte
[] { (
byte
)(cut?2:5),0,0,0};
memo.Write(bytes,0,bytes.Length);
data.SetData(
"PreferredDropEffect"
,memo);
Clipboard.SetDataObject(data,
false
);
}