This may seem like a rather obvious and extremely newcomer question (and it is), but I've merely been attempting to transition between multiple forms in C# Winforms and somehow managed to encounter numerous complications:
frm_hub hub = new frm_hub(); hub.Show();
However, each time this code run, a new instance of frm_hub was created and using hub.Close(); would not work because it was not closing the same new instance of frm_hub
frm_hub hub = new frm_hub(); private void OpenForm() { hub.Show() }
However the runtime error: 'System.StackOverflowException: 'Exception of type 'System.StackOverflowException' was thrown.' was showing when I attempted to use this same tactic of storing the form as a variable in the two forms.
However, my attempt of this required the use of anchors to get the form to display remotely true to the Designer appearance
Apologies again for my beginner understanding and use of terminology, feel free to seek clarification for crucial details I probably haven't included haha, Thank you!
I used the following, not sure it's best practice. I used a button ShowFrmHubButton
and disabled it when the window is already shown.
In my example the second form is modal, and you can't use the first window as long as the second is displayed.
ShowFrmHubButton.IsEnabled = false;
var frmHubWindow = new frm_hub ()
{
Owner = this
};
frmHubWindow.ShowDialog();
ShowFrmHubButton.IsEnabled = true;
Then, when you close\cancel the second form use this.Close();