@LWY , Welcome to Microsoft Q&A, We could use command line to pass the parameters to running process.
First, I make the following code to check if the parameters' count is more than 1.
Code example:
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length> 1)
{
Application.Run(new Form1());
}
else
{
Application.Run(new Form2());
}
}
Second, Please try the following command to pass the parameters to winform project:
CD E:\WindowsFormsApp1\bin\Debug (Your project path)
E:\WindowsFormsApp1\bin\Debug>WindowsFormsApp1.exe test1 test2
E:\WindowsFormsApp1\bin\Debug>WindowsFormsApp1.exe test1
Result1:
Result2:
Hope my answer could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.