简体   繁体   中英

Windows Forms Application - Error creating window handle

Code in Form1.cs: In which, I hid Form1.cs then showed Form2.cs

private void Form1_Load(object sender, EventArgs e)
{
    this.Hide(); 
    Form2 f2 = new Form2();
    f2.Show();
}

Code in Form2.cs: In which, I hid Form2.cs and tried to show Form1.cs again then the Error creating window handle appeared on runtime.

private void Form2_Load(object sender, EventArgs e)
{
    this.Hide();
    Form1 f1 = new Form1();
    f1.Show();
}
  • When loading Form1, you show a new, additional Form2.
  • When loading Form2, you show a new, additional Form1.

This is a circle. It's creating new Forms as fast as it gets, each Form1 a Form2 and each Form2 a new Form1 and then it starts the circle again until there is no more window Handles left to create new windows.

I'm not really sure what you want to do, but this is not the way to do it. Describe what you want to do and maybe we can help.

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