2

I was creating a Photo Viewer in C# winform and I was using the openfiledialog to open files in it. But then I thought to make it work as a proper photo viewer if anyone click on its image file eg png, jpg, gif. It opens it in my photo viewer. Or ask it choose it as default photo viewer or open with this app. So there would definitely be some code to open files in such manner, and would also be some process to go through while publishing it to tell the OS that is a photo viewer. An help on how to do this. Also is the process for the text editors and other things like this is same.

mega6382
  • 9,211
  • 17
  • 48
  • 69

1 Answers1

3

This is a setting in Windows, and is not directly controlled by your program. See here for instructions on how to change this on your PC. If you're distributing your application using an installer, you can have the installer set program associations for you.

Jon B
  • 51,025
  • 31
  • 133
  • 161
  • Thanks Jon, but what I am really asking is when you double click on the image file and it opens in my photo viewer how do I control it like in `openfiledialog()` we can use a property `filename` to get the path to the file. How can we do this by double clicking it. – mega6382 Apr 15 '14 at 17:45
  • @mega6382 your program needs an argument for the filename. When your program launches, you look for this argument, and handle it the same way you're handling the filename from the openfiledialog. You may need to add `params string[] args` to your `Main()`. – Jon B Apr 15 '14 at 17:50
  • This is not C++ this is C# it does not have constructors name as `main()` it uses the class name as the constructor. So can you tell me the syntax for C#. Or is it same on both? – mega6382 Apr 15 '14 at 17:56
  • Unless you've modified it, your WinForms project has a file called Program.cs with a function called `Main()`. If it's missing `params string[] args`, just add that. – Jon B Apr 15 '14 at 17:58
  • See also: http://stackoverflow.com/questions/1179532/how-do-i-pass-command-line-arguments-to-a-winforms-application – Jon B Apr 15 '14 at 18:01