简体   繁体   中英

Confusing in event Form_Load

private void Form1_Load(object sender, EventArgs e)
    {
        MessageBox.Show("Luanching.... This may take a few second");
............
    }

Here if I don't click OK in messagebox my from will not show up (It will wait until me click) how to fix this how to make form show up first or how to make doesn't wait for click OK

Simple, Just move the MessageBox code to Shown event

private void Form1_Shown(object sender, EventArgs e)
{
    MessageBox.Show("Luanching.... This may take a few second");
}

Another option is to place a backgroundworker on the form. Then in the events, doubleclik on 'DoWork' in the method that is then created in code, place the messagebox.show. This way the messagebox is shown in a separate thread and the loading of the form will continue

You don't need to use MessageBox , you have to create a new Form which shows a message. New Form will run on a new message loop, so will not block ui, if call it like

myForm.Show() , where myForm is your form's instance.

The event Form1_Load is exaclty what it sounds, so if you insert some sort of MessageBox there, the Form will only load after the response.

Consider using another method, after the Form load.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM