拖&放;降动态创建的快捷方式 [英] Drag & drop of a dynamically created shortcut

查看:180
本文介绍了拖&放;降动态创建的快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#应用程序创建的快捷方式,以启动与特定的参数和初始目录的其他程序。我希望用户能够从Windows窗体拖动一个快捷方式拖放到任意位置相关的如桌面,开始菜单,等等,但我真的不知道如何处理,任何人都可以点我的正确的方向?

I have a C# application that creates shortcuts to launch other programs with specific arguments and initial directories. I would like the user to be able to drag a shortcut from the Windows form and drop it anywhere relevant like the desktop, the start menu, and so on but I don't really know how to handle that, could anyone point me in the right direction?

我已经看到了使用PInvoke的几件样品,并的IShellLink 喜欢<一href="http://vbaccelerator.com/home/NET/$c$c/Libraries/Shell%5FProjects/Creating%5Fand%5FModifying%5FShortcuts/ShellLink%5F$c$c.asp"相对=nofollow>这个,或读答案的那么像<一个href="http://stackoverflow.com/questions/1501608/how-do-you-create-an-application-shortcut-lnk-file-in-c-with-command-line-arg">here,这已经帮助创建快捷方式,并将其保存在一个.lnk文件。我想我有当用户通过处理一个的MouseDown 的DoDragDrop()呼叫数据C $ C>信号。这是据我得到的,我想我需要确切地知道哪种类型的目标是希望接受的下降,以及如何序列化的捷径,但无法找到该部分的任何信息。

I have seen a few samples using PInvoke and IShellLink like this one, or read answers on SO like here, which already help create shortcuts and save them in a .lnk file. I assume I have to hand over data in a DoDragDrop() call when the user initiates a drag operation, for example by handling a MouseDown signal. That's as far as I got, I suppose I need to know exactly which type the target is expecting to accept the drop, and how to serialize the shortcut, but couldn't find any information on that part.

也许另一种选择是将得到下降的位置,并管理从我的应用程序,但有一次我有点无能,如何做到这一点。

Perhaps another option would be to get the location of the drop, and manage that from my application, but there again I'm a bit clueless as how to do that.

该框架的版本是目前3.5,而我只考虑Windows平台。

The framework version is currently 3.5, and I'm only considering Windows platforms.

在此先感谢您的帮助!


更新/解决方案:

使用<一个href="http://vbaccelerator.com/home/NET/$c$c/Libraries/Shell%5FProjects/Creating%5Fand%5FModifying%5FShortcuts/ShellLink%5F$c$c.asp"相对=nofollow> ShellLink code 上述创建一个临时的快捷方式文件,我只是用数据对象在拖放一样下面的例子:

Using the ShellLink code mentioned above to create a temporary shortcut file, I simply used DataObject for the drag and drop, like in the following example:

private void picShortcut_MouseDown(object sender, MouseEventArgs e)
{
    ShellLink link = new ShellLink();

    // Creates the shortcut:
    link.Target = txtTarget.Text;
    link.Arguments = txtArguments.Text;
    link.Description = txtDescription.Text;
    link.IconPath = txtIconFile.Text;
    link.IconIndex = (txtIconIndex.Text.Length > 0 ?
        System.Int32.Parse(txtIconIndex.Text) : 0);
    link.Save("tmp.lnk");

    // Starts the drag-and-drop operation:
    DataObject shortcut = new DataObject();
    StringCollection files = new StringCollection();
    files.Add(Path.GetFullPath("tmp.lnk"));
    shortcut.SetFileDropList(files);
    picShortcut.DoDragDrop(shortcut, DragDropEffects.Copy);
}

如果你考虑到的PInvoke code(这里没有显示),而我还需要创建一个目标名称该临时文件相当复杂。如果有人知道......呃,快捷方式,它的欢迎!或许到移植的code,对于它John Knoeller 给了一个链接(感谢!)。

Quite complicated if you consider the PInvoke code (not shown here), and I still need to create this temporary file with the target name. If anyone knows a... erm, shortcut, it's welcome! Perhaps by porting the code for which John Knoeller gave a link (thanks!).

推荐答案

雷蒙德陈没上他的博客这个题目一整篇文章退房的拖动一个虚拟文件

Raymond Chen did a whole article on this very topic on his blog check out dragging a virtual file

这篇关于拖&放;降动态创建的快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆