Wednesday, May 21, 2014

how to set start page in windows application using c#.net in 2010

Description:

 I didn’t worked on windows application one day we got requirement to work on windows application at that time I don’t’ know anything about windows application even how to set startup page in windows application. I have searched many websites for this after search long time I found answer for this partially.

At that time I decided to write this post because some of the people who don’t know how to set start up page in windows application for those people it gives idea to set start up page.
Open visual studio and create new windows application by default it will create Form1.CS page now if we run application Form1.CS runs by default but if we add another page to our project and we need to set that page as start up page at that time we will get problem for that we need to follow these steps.
To set our page as start up page that page needs to contain following code in the program.cs

***************************************
static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new YourFormName());
            Application.Run(new Login());
            if (Login.IsLogin == 1)
            {
                Application.Run(new MDI_main());
            }
            else
            {
                Application.Exit();
            }
        }
***************************************

Application.Run(Form) methodBegins running a standard application message loop on the current thread, and makes the specified form visible.

YourFormName() add your form name (whatever the page name you have given at the time creation of page) and Add this Main () method in all of your pages after that you will get all the pages list in Startup object list there we have chance to select particular page as start up page. After completion of adding this Main method follow the below steps.



Note :- i am using start page from login so you must put your logic in login.cs page.

No comments:

Post a Comment