How can I get args of Form program? In console application I can use args[]
but what about Form Application?
One simple way:
string[] args = Environment.GetCommandLineArgs();
Alternatively you could change the Main-call to include parameters (in Program.cs):
static void Main(string[] args)
{
You will then need to pass it into your Form, and change your form's constructor accordingly (assuming that's where you need the args
):
public Form1(string[] args)
{
When you create a WinForm application in C# the editor creates a Program.cs file for you. That is where main is located and that is where the arguments are available.
It's a bit of IDE "magic" for lack of a better term. There is still a 'main' function, it just launches an instance of your main form does and anything else that is required for you. Open that file up and take a look.
You need to change the form constructor to accept an args parameter.
eg:
public void Form1(string[] args)
{
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.