c#form drag(不删除)文件onclick

发布于 2025-02-09 09:22:45 字数 686 浏览 1 评论 0原文

我希望,当您激活元素的onclick事件时,它会给我一个附加到鼠标的文件,例如使用拖放功能时。

我不想放下文件,我想从表单中拖动它,有什么方法可以做到这一点?

编辑: 我已经取得了一些进步...这是我的onclick事件的代码:

    private void DragArchivo(object sender, MouseEventArgs e)
    {
        DoDragDrop(File.Create(ruta), DragDropEffects.Copy | DragDropEffects.Move);
    }

我有一个名为ruta的根源,指向AC#脚本:

C:\\Users\\Usuario\\Documents\\GitHub\\blabla\\blablaCommand.cs

这已经适用于拖动字符串之类的东西,但我不能这样做。

顺便说一句,观点是从我的程序中获取文件并将其放入Visual Studio中以工作: “在此处输入图像说明”

I want that when you activate the onclick event of an element it gives me a file attached to my mouse like when you use the drag And Drop function.

I dont want to drop a file, i want to drag it from the form, there is some way to do this?

Edit:
I have made some progress... this is my code now for the onclick event:

    private void DragArchivo(object sender, MouseEventArgs e)
    {
        DoDragDrop(File.Create(ruta), DragDropEffects.Copy | DragDropEffects.Move);
    }

I have an absolute root named ruta that point to a c# script:

C:\\Users\\Usuario\\Documents\\GitHub\\blabla\\blablaCommand.cs

This already works for dragging things like strings but i cant do it work whit files.

By the way, the objetive is to grab files from my program and drop them into visual studio to work whit it:enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恍梦境° 2025-02-16 09:22:45

如果某人将来有同样的问题,这里是一个非常酷的人,它找到了解决方案:

“ rel =“ nofollow noreferrer”我最终使用的是:

DataObject dragObject = new System.Windows.Forms.DataObject();
StringCollection filePaths = new StringCollection();
filePaths.Add(ruta);
dragObject.SetFileDropList(filePaths);
DoDragDrop(dragObject, DragDropEffects.Copy | DragDropEffects.Move);

If someone has the same problem in the future here is a very cool person that has found the solution:
https://www.codeproject.com/Questions/576279/DragplusfileplusOUTplusofplusapplication

The code that i have finaly used is:

DataObject dragObject = new System.Windows.Forms.DataObject();
StringCollection filePaths = new StringCollection();
filePaths.Add(ruta);
dragObject.SetFileDropList(filePaths);
DoDragDrop(dragObject, DragDropEffects.Copy | DragDropEffects.Move);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文