title: Open up Windows Form from within another Windows Form and detect button click
body: <p>I'm learning how to use Windows Forms currently. I have a main Windows Form (MainForm) that controls everything. At a certain point during execution, I want to open up another Windows Form that contains a Listbox (ListboxForm) and a button (DoneButton) that indicates when the user is done with ListboxForm. I've managed to get ListboxForm to show up, but I'm unsure of how to make MainForm wait and continue execution after the user presses DoneButton. </p>
  
  <p>Right now, when ListboxForm pops up and the user clicks DoneButton, ListboxForm is still displayed and nothing happens. I'm unsure of why this is happening - I have a this.close in the button code for DoneButton. </p>
  
  <p>Here's my code for ListboxForm:</p>
  
  <pre><code>public partial class ListboxForm : Form
  {
      List&lt;string&gt; _items = new List&lt;string&gt;();
  
      public UpdateGhubAndWebConfigForm()
      {
          InitializeComponent();
  
          _items.Add("Option 1");
          _items.Add("Option 2");
          _items.Add("Option 3");
  
          listBox1.DataSource = _items;
      }
  
      private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { }
  
      // This is for 'DoneButton'
      private void button1_Click(object sender, EventArgs e)
      {
          LoggingProvider.Log.Info("ListboxForm DoneButton clicked with index: " + listBox1.SelectedIndex.ToString());
  
          DoStuff();
  
          this.Close();
      }
  
      private void Form1_Load(object sender, EventArgs e) { }
  
      private void label1_Click(object sender, EventArgs e) { }
  
      public static void DoStuff() { }
  }
  </code></pre>
  
  <p>and MainForm opens/creates a ListboxForm like this:</p>
  
  <pre><code>if(displayListboxForm == true)
  {
      var listboxForm = new ListboxForm();
      listboxForm.ShowDialog();
  
      // Now I want MainForm to wait until the user clicks DoneButton in ListboxForm
      MessageBox.Show("User has selected an option from ListboxForm");
  }
  </code></pre>