Cut files to clipboard in C#

前端 未结 3 1492
自闭症患者
自闭症患者 2020-12-06 02:06

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 Expl

3条回答
  •  一向
    一向 (楼主)
    2020-12-06 02:44

    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);
    

提交回复
热议问题