Saturday 4 June 2016

Call Winforms Forms application from console application and pass the input parameters

In this post we are going to see how to call a winforms application from a console application and pass the input paramteres to the winforms

First we develop a Winforms application with one form where it will have two textbox which is a username and password.

Winforms Design:
******************





Winforms Code :
******************

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            var data = Environment.GetCommandLineArgs();

            if (data.Length == 3)
            {
                textBox1.Text = data[1];
                maskedTextBox1.Text = data[2];
            }
        }
    }

In the above you can see that i am assigning the index 1 and 2 , because on 0 index CommandLingArgs will have the path of the Executable in winforms 



Console Application :
******************
Create a new project in console application, then create the following code , which will invoke the instance of a process.

            Process pro = new Process();
            pro.StartInfo.FileName = @"C:\amApp\ParamApp\bin\Debug\ParamApp.exe";
            pro.StartInfo.Arguments = "Rajesh Password";
            pro.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
            pro.Start();
            pro.WaitForExit();


Output:
***********





In this post we can see how to call a winforms application from the Console application

No comments:

Post a Comment