标签: c# .net drag-and-drop
如何实现在程序图标上拖动任意文件图标的效果?也就是说,我想这样做,如果我将文件拖到我的程序,程序启动并打开该文件。在图中,MyProgram是我编写的C#程序。文件是我要打开的文件。
答案 0 :(得分:1)
正如Jens评论的那样,您可以检查Environment.GetCommandLineArgs,或者您可以使用主方法参数:
Environment.GetCommandLineArgs
public static void Main(string[] args) { if (args.Length > 0) Console.WriteLine(args[0]); // Here's the file path }