Yes, this code is a hassle. This happens incorrectly when the user closes the dialog. Then Windows should find another window where you can concentrate. There is nothing left in your application, the main window is invisible. Then he selects the window of another application. The odds are good, for example, that it will be a window inside Visual Studio. Large. Your basic form now disappears behind it.
You need to make sure your main window displays again before the dialog box closes. You can do this by subscribing to the FormClosing event handler dialog. For instance:
private void button1_Click(object sender, EventArgs e) { using (var dlg = new Form2()) { dlg.StartPosition = FormStartPosition.Manual; dlg.Location = this.Location; dlg.FormClosing += (s, ea) => this.Show();
source share