My project is a console client. I start in the console and then display the form. I use the code below to display a blank form (I will add controls later) to the user. But the form is displayed, but it is stuck (not active). What should I do?
Console.WriteLine("Starting form");
Console_Client.Main mainform = new Main();
mainform.Show();
Console.ReadLine();
Try ShowDialog().
The problem is that you're not running a message loop. There are two ways to start one. ShowDialog() has one integrated so that will work. The alternative is to use Application.Run(), either after the Show() call or with the form as a parameter.
ShowDialog():
mainform.ShowDialog();
Application.Run() without form:
mainform.Show();
Application.Run();
Application.Run() with the form:
Application.Run(mainform);
All of these work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With