How can i minimize application to system tray by using command line argument.
eg:when i open my application using command line like this.
c:\myfile.exe totray
i writed some code for that but it never worked.
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length >0)
{
MessageBox.Show(args[0]);
}
Application.Run(new Form1());
}
Here the messagebox is showing with my argument “totray”.
so i just added code like
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length >0)
{
// MessageBox.Show(args[0]);
if (args[0] == "totray") {
Form1 frm1 = new Form1();
frm1.Hide();
}
}
Application.Run(new Form1());
}
But this idea is not working.
is it possible to do get the argument to the form?
what code i need to write here?
Environment.CommandLinecontains the arguments passed on the command line.Better Environment.GetCommandLineArgs() that returns a string array like the string[] args passed to the main method, but with the first argument being the executable file name.
Not sure if you need moving the code to the form_load event or in the form contructor.
MSDN Refs