简体   繁体   中英

C# How to pause Form1 while Form2 is active?

As the title says; that's all I need. I have 2 forms : Form1 and Form2 . At some point of my code I want to do Form2.ShowDialog() and after Form2 is closed I want to resume Form1. How can i do this?

I tried using Thread.Sleep(sometime) but this will just disable any controls,timers, etc from Form1 and resume after the period passed. The problem is that I cant know how much time it will take for my user to press something in Form2.

As per KDecker mentioned in a comment to your question:

If you want to show something Modally (that is the form behind is unusable) use the ShowDialog() method. This will make it so you can only use the form that ShowDialog() was called on.

If you want to show it Modeless, then just use the Show() method on Form. This will make it so you can use both forms

See the MSDN documentation for reference: https://msdn.microsoft.com/en-us/library/aa984358(v=vs.71).aspx

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