user11348254
user11348254

Reputation:

Form Load not working after Application.Run method

I'm trying to perform a function after Application.Run in main method. I have added code for Form_Load but it doesn't seem to be working.

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        var frm1 = new LoginM();
        frm1.Load += LoginFormLoad;
        Application.Run(frm1);
    }

    private static void LoginFormLoad(object sender, EventArgs e)
    {
        LoginM test = new LoginM();
        test.LoginExistingusers();

    }
    public void LoginExistingusers()
    {
        mtxtPassword.Text = "Form has loaded";
        MbtnLogin.Click += new System.EventHandler(MbtnLogin_Click);
    }

Upvotes: 0

Views: 133

Answers (1)

Selim Yildiz
Selim Yildiz

Reputation: 5370

You can use Form.Load Event:

Also you should use sender parameter instead of creating new instance of LoginM

static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    var frm1 = new LoginM();
    frm1.Load += LoginFormLoad;
    Application.Run(frm1);

}

static void LoginFormLoad(object sender, EventArgs e)
{
    (sender as LoginM).LoginExistingusers();
}

Upvotes: 1

Related Questions