在C#中打开GTK窗口,返回数据并关闭窗口,然后打开另一个窗口?

在C#中打开GTK窗口,返回数据并关闭窗口,然后打开另一个窗口?,c#,gtk,C#,Gtk,我正在使用C#with GTK编写一个主窗口包含按钮的应用程序。当按下其中一个按钮时,它将调用一个事件处理函数,该函数将打开一个新窗口,其中包含供用户填写的表单。到目前为止,一切都很好 我遇到的问题是,我需要让这个事件处理函数打开这个窗口,等待它被填充并关闭,然后打开第二个窗口,等待它被填充并关闭,然后处理所有捕获的数据。 我已经做了一个简单的例子来说明我的意思(我理解在下面的例子中,打开一个带有两个组合框的窗口会更有意义,但那是因为这只是一个例子!) 上述情况下,两个窗口同时打开,标签立即用默

我正在使用C#with GTK编写一个主窗口包含按钮的应用程序。当按下其中一个按钮时,它将调用一个事件处理函数,该函数将打开一个新窗口,其中包含供用户填写的表单。到目前为止,一切都很好

我遇到的问题是,我需要让这个事件处理函数打开这个窗口,等待它被填充并关闭,然后打开第二个窗口,等待它被填充并关闭,然后处理所有捕获的数据。 我已经做了一个简单的例子来说明我的意思(我理解在下面的例子中,打开一个带有两个组合框的窗口会更有意义,但那是因为这只是一个例子!)

上述情况下,两个窗口同时打开,标签立即用默认数据更新,而不是在两个窗口中选择的数据。所以我有两个问题:

1) 如何让它打开WindowOne,等待数据被检索,然后打开WindowII,等待数据被检索,然后更新标签

2) 如何编辑“OnSend”函数,使其在调用SetFavDrink/SetFaveCheese函数后关闭窗口


有人能给我指一下这里的正确方向吗?我对这种编程百灵鸟还不熟悉,所以要温柔

我想这就是你想要的(注意,这可能会被清理掉……):

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));
        }
    }
}
using System;
using Gtk;


    namespace WaitingTest
    {
        public class MainClass
        {       
            static void Main (string[] args)
            {
                Application.Init ();
                new MenuWindow();
                Application.Run();
            }
        }
        public class MenuWindow
        {
            public static string favDrink = "Water";
            public static string favCheese = "Chedder";
            public 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
                new WindowOne();
            }

            public static void SetFavDrink(string d)
            {
                MenuWindow.favDrink = d;
                Console.WriteLine(favDrink);
            }

            public static void SetFavCheese(string c)
            {
                MenuWindow.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;
            static Window w1 = new Window ("Window One");
            public WindowOne ()
            {


                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);
                WindowOne.w1.Destroy();
                new WindowTwo();

            }

            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;
            static Window w2 = new Window ("Window Two");
            public WindowTwo ()
            {


                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);
                WindowTwo.w2.Destroy();
                MenuWindow.output.Text="Drink: "+MenuWindow.favDrink+"\nCheese: "+MenuWindow.favCheese;
            }

            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));
            }
        }
    }

`