18 February 2014

APPLICATION.RUN() c#.net



For any forms application, there must be starting point.
.NET refers the program class which will be created automatically for forms application.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace adi
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new form1());
        }
    }
}


Application.Run(new object()) will start the corresponding object for the first execution.

ForgetCode shows here the code to light upon the execution flow for different objects.

Consider, you have created 3 forms with the object names form1,form2,form3.
If you have created form1 at first then Run() will automatically pickup the form1 object.

Application.Run(new form1())

But you want to execute the form3 at first. What will you do?
Simple. You can simply replace the existing object with new one.

Application.Run(new form3())

No comments:

Post a Comment