1

I have a winform application with 2 forms, I am calling one form MainForm from PasswordForm.

First I set the constructor

private MainForm mainForm = new MainForm();

Then I show the form

mainForm.Show();

However, there is about a 2 second delay in loading the form, because of a number of SQL queries that run on the form load event.

Is there any way I can call an event after the mainForm is shown? (specifically I want to fade out the PasswordForm, which I currently use this

FadeOut(this, 100);

I've tried calling from the MainForm_Shown event but haven't found a way of referring to the PasswordForm form?

    private void MainForm_Shown(object sender, EventArgs e)
    {
        // THIS WILL FADE OUT THE 'MAINFORM' BUT I WANT TO FADE OUT THE 'PASSWORDFORM'
        FadeOut(this, 100);
    }

EDIT Both forms are using the same namespace.

Brendan Gooden
  • 1,460
  • 2
  • 21
  • 40
  • Follow the steps here to pass a reference of 1 form to another : http://stackoverflow.com/a/38460510/3185569 then call any public method of that form. – Zein Makki Jul 20 '16 at 05:48

1 Answers1

-1

Use open forms:

private void MainForm_Shown(object sender, EventArgs e)
{
    dynamic frm = Application.OpenForms["mainForm"];
    frm.FadeOut(this, 100);
}
Aimnox
  • 895
  • 7
  • 20