I am programming, in Microsoft's Visual Studio 2015, in C#.
I am trying to make an Windows Forms application which would be used to open simple .txt, or other type files, and edit them.
But the point being is i want to open my program with : Right click on .txt file->Open with->My program.
The question I have is this, how am I supposed to do that, if I only have the solution file of my program? And i don't really care, about opening the .txt files when my program is already running. I want to be able to start it, like i mentioned before.
I am using this program as a starting point, from where the next time i will be able to make a simple mp3 player, or such. And as far as i know, people don't usually start an mp3 player program, and then the mp3 player file they want to play. I hope that sheds some light on what i am trying to accomplish.
I have been searching for a solution, and i couldn't find it. Perhaps it is really easy, but for me, for now, it isn't. Your help is appreciated.
My Program.cs looks like this :
static void Main(string[] args)
{
//with args(user open file with the program)
if(args != null && args.Length > 0)
{
string fileName = args[0];
//check file exists
if (File.Exists(fileName))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 MainForm = new Form1();
MainForm.OpenFile(fileName);
Application.Run(MainForm);
}
//the file does not exist
else
{
MessageBox.Show("The file does not exist!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
//without args
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}