如何将文件拖动到我创建的exe文件(拖放图标)并在exe开始运行时将其作为参数?

时间:2021-01-10 19:41:53

how can I drag a file to an exe I create (drag and drop over the Icon) and have it as an argument when the exe start running ?

如何将文件拖动到我创建的exe文件(拖放图标)并在exe开始运行时将其作为参数?

1 个解决方案

#1


If you make this following code, then when you drag your file onto the exe icon, the args[0] will have the path of it as an argument: (I added the if statement that if you start the program without dragging anything it shouldn't crash)

如果您使用以下代码,那么当您将文件拖到exe图标上时,args [0]会将其路径作为参数:(我添加了if语句,如果您启动程序而不拖动它应该不会崩溃

class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.WriteLine(args[0]);
            }
            Console.ReadLine();
        }
    }

#1


If you make this following code, then when you drag your file onto the exe icon, the args[0] will have the path of it as an argument: (I added the if statement that if you start the program without dragging anything it shouldn't crash)

如果您使用以下代码,那么当您将文件拖到exe图标上时,args [0]会将其路径作为参数:(我添加了if语句,如果您启动程序而不拖动它应该不会崩溃

class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.WriteLine(args[0]);
            }
            Console.ReadLine();
        }
    }