Hi,


I have develop a program in C# windows Application & now The problem is My Login form is designed on form4 I want to run form4 first after that i want to run the other forms but when i run the program form1 is run automatically. acually in coding I have run the form1 after form4

I use the code for

In form4

form1 fr1 = new form1();
fr1.show();

Why it happends what is the solution for this problem

tahnk u

virusisfound

In the solution explorer double click Program.cs (or right click and "View Code")

There you will find:

Application.Run(new Form1());

now change it to:

Application.Run(new Form4());

ereruh's post would mean the application closes when Form4 closes.

If the login dialog is only required at the start of the application then one solution is to open the login form before the Application.Run in program.cs as below.

DialogResult result;
using(Form4 loginDialog = new Form4())
{
    result = loginDialog.ShowDialog();
}
if (result == DialogResult.OK)
    Application.Run(new Form1());

Another solution is to open the login form in Form1.Load

private void Form1_Load(object sender, EventArgs e)
{
    DialogResult result;
    using(Form4 loginDialog = new Form4())
    {
        result = loginDialog.ShowDialog();
    }
    if (result != DialogResult.OK)
        this.Close();
}

Note: the above samples assume that Form4 is a dialog and returne DialogResult.OK if the login is OK. You will need to adjust the code to suit how your Form4 works.

This article has been dead for over six months. Start a new discussion instead.