Loading

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);
        }
posted @ 2013-06-08 21:33  Sam Xiao  阅读(1035)  评论(0编辑  收藏  举报