I am a newbie, so it might seems a silly question.

I have a login form which calls other form where it says .. "please wait while it loads".

in form 2 i have a label for that.

Now the problem is that the text for that label doesnot appears until everything is executed in the login_click event.

Ex:

private void cmdLogin_Click(object sender, EventArgs e)
{
    frm2 objfrm = new frm2();
    frm2.show();

    // Manything to execute.
    
   frm2.close();
}

Now it loads form2 but the label text doesnot appears.

I removed frm2.close() and came to know that after it comes out of the cmdLogin_Click function, it the text appears.

I also tried frm2.showdialog(), which loads the text but the code stops at that line and doesnot move to next line in the function cmdLogin_Click.

Is there any solution for this?

Help would be appreciated.

Recommended Answers

All 2 Replies

The problem is that "manything to execute" is not allowing the UI thread any time to draw frm2. Put Application.DoEvents(); right after your frm2.Show() command. That should allow the UI thread to finish showing your frm2.

Thanks .. that solved the problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.