title: Open GTK Window in C#, return data and close Window, Then Open Another Window?
body: <p>I'm using C# with GTK to write an application with a main window containing buttons.  When one of the buttons is pressed, it calls an Event Handler function which opens up a new window containing a form for the user to fill in.  So far, all working so good.</p>
  
  <p>What I'm having problems with is that I need to have this Event Handler function open up this window, wait for it to be filled in and closed, then open a second window, wait for it to be filled in and closed, then process all this captured data.
  I've made a simple example to show what I mean (I understand in the below example it would make more sense to open one window with two combo boxes, but that's because this is just an example!)</p>
  
  <pre><code>using System;
  using Gtk;
  
  namespace WaitingTest
  {
      public class MainClass
      {       
          static void Main (string[] args)
          {
              Application.Init ();
              MenuWindow myWindow = new MenuWindow();
  
              Application.Run();
          }
      }
  
      public class MenuWindow
      {
          static string favDrink = "Water";
          static string favCheese = "Chedder";
          static Label output = new Label();
  
          public MenuWindow()
          {
              Application.Init ();
  
              Window test = new Window ("Main Window");
  
              VBox vb = new VBox();
              Button getData = new Button("Get Data");
              Button quitApp = new Button("Quit");
  
              getData.Clicked += OnGetData;
              quitApp.Clicked += OnExit;
  
              vb.PackStart(getData, false, false, 1);
              vb.PackStart(quitApp, false, false, 1);
              vb.PackStart(output, false, false, 1);
  
              test.Add(vb);
              test.ShowAll();
  
              Application.Run();
          }
  
          static void OnGetData(object sender, EventArgs args)
          {
              // Open up Window to select drink
              WindowOne w1 = new WindowOne();
  
              // Open up Window to select cheese
              WindowTwo w2 = new WindowTwo();
  
              // Display results in label
              output.Text="Drink: "+favDrink+"\nCheese: "+favCheese;
          }
  
          public static void SetFavDrink(string d)
          {
              favDrink = d;
              Console.WriteLine(favDrink);
          }
  
          public static void SetFavCheese(string c)
          {
              favCheese = c;
              Console.WriteLine(favCheese);
          }
  
          static void OnExit(object sender, EventArgs args)
          {
              Application.Quit();
          }
  
          protected void OnDeleteEvent(object sender, DeleteEventArgs a)
          {
              Application.Quit ();
              a.RetVal = true;
          }   
      }
  
      class WindowOne
      {
          ComboBox drink = ComboBox.NewText();
          static string choice;
  
          public WindowOne ()
          {
              Window w1 = new Window ("Window One");
  
              VBox vb = new VBox();
  
              Button sendDrink = new Button("Send Drink");
  
              sendDrink.Clicked += OnSend;
              drink.Changed += new EventHandler(onDrinkChanged);
  
              drink.AppendText("Beer");
              drink.AppendText("Red Wine");
              drink.AppendText("White Wine");
              drink.AppendText("Whiskey");
  
              vb.PackStart(drink, false, false, 1);
              vb.PackStart(sendDrink, false, false, 1);
  
              w1.Add(vb);
              w1.ShowAll();
          }
  
          void OnSend(object sender, EventArgs args)
          {
              WaitingTest.MenuWindow.SetFavDrink(choice);
          }
  
          void onDrinkChanged(object o, EventArgs args)
          {
              ComboBox combo = o as ComboBox;
              if (o == null)
                  return;
  
              TreeIter iter;
  
              if (combo.GetActiveIter (out iter))
                  choice = ((string) combo.Model.GetValue (iter, 0));
          }
      }
  
      class WindowTwo
      {
          ComboBox cheese = ComboBox.NewText();
          static string choice;
  
          public WindowTwo ()
          {
              Window w2 = new Window ("Window Two");
  
              VBox vb = new VBox();
  
              Button sendCheese = new Button("Send Cheese");
  
              sendCheese.Clicked += OnSend;
              cheese.Changed += new EventHandler(onCheeseChanged);
  
              cheese.AppendText("Gorgonzola");
              cheese.AppendText("Edam");
              cheese.AppendText("Brie");
              cheese.AppendText("Feta");
  
              vb.PackStart(cheese, false, false, 1);
              vb.PackStart(sendCheese, false, false, 1);
  
              w2.Add(vb);
              w2.ShowAll();
          }
  
          void OnSend(object sender, EventArgs args)
          {
              WaitingTest.MenuWindow.SetFavCheese(choice);
          }
  
          void onCheeseChanged(object o, EventArgs args)
          {
              ComboBox combo = o as ComboBox;
              if (o == null)
                  return;
  
              TreeIter iter;
  
              if (combo.GetActiveIter (out iter))
                  choice = ((string) combo.Model.GetValue (iter, 0));
          }
      }
  }
  </code></pre>
  
  <p>What happens with the above is that both windows open at once and the label is updated immediately with the default data, rather than the data that will be selected in the two windows.  So I have two questions:</p>
  
  <p>1) How can I get it to open WindowOne, wait until the data is retrieved, then open WindowTwo, wait until the data is retrieved, then update the label?</p>
  
  <p>2) How can I edit the "OnSend" functions so it will close the window after calling the SetFavDrink/SetFaveCheese function?</p>
  
  <p>Could someone please point me in the right direction here?  I'm new to this programming lark, so be gentle!</p>