0

How can I achieve the effect of dragging an arbitrary file icon on the icon of my program? That is, I want to make it so that if I drag a file to my program, the program starts and opens this file. In the figure, MyProgram is a program in C # that I write. File is the file I want to open.

enter image description here

Filburt
  • 17,626
  • 12
  • 64
  • 115
Dmitrii Kurylev
  • 407
  • 1
  • 8
  • 17
  • 4
    The default effect of this is that the filename is passed as a command line argument. Check the CommandlineArgs and handle the opening on program start. – Jens Mar 26 '17 at 18:09
  • Possible duplicate of [How do I drag and drop files into an application?](http://stackoverflow.com/questions/68598/how-do-i-drag-and-drop-files-into-an-application) – ComputersAreCool Mar 26 '17 at 18:14
  • Hooray! Thanks, it's beautiful! This is what I need! :) – Dmitrii Kurylev Mar 26 '17 at 18:17

1 Answers1

1

As Jens commented you may check Environment.GetCommandLineArgs or you can just use main method arguments:

public static void Main(string[] args)
{
    if (args.Length > 0)
          Console.WriteLine(args[0]); // Here's the file path
}
align
  • 351
  • 2
  • 9