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 @ 2014-06-27 14:43  b̶i̶n̶g̶.̶  阅读(432)  评论(0编辑  收藏  举报