Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 简单窗口:为什么不显示动态生成的按钮?_C#_Gtk# - Fatal编程技术网

C# 简单窗口:为什么不显示动态生成的按钮?

C# 简单窗口:为什么不显示动态生成的按钮?,c#,gtk#,C#,Gtk#,我有一个简单的GTK窗口:它只包含一个按钮 如果单击此按钮,我想创建另一个按钮,该按钮应显示在同一窗口中 我的问题是:生成的按钮从未在GUI上显示,尽管它已添加到我的“窗口”对象中。 如果我直接在构造函数中调用它,我用来创建按钮的函数可以正常工作,所以它应该是正常的 我的简单应用程序中缺少哪些代码,从而显示生成的按钮 class TestWindow : Window { private Fixed _fix = new Fixed(); public

我有一个简单的GTK窗口:它只包含一个按钮

如果单击此按钮,我想创建另一个按钮,该按钮应显示在同一窗口中

我的问题是:生成的按钮从未在GUI上显示,尽管它已添加到我的“窗口”对象中。 如果我直接在构造函数中调用它,我用来创建按钮的函数可以正常工作,所以它应该是正常的

我的简单应用程序中缺少哪些代码,从而显示生成的按钮

class TestWindow : Window
    {
        private Fixed _fix = new Fixed();

        public TestWindow() : base("Test window")
        {
            SetDefaultSize(250, 200);
            SetPosition(WindowPosition.Center);

            DeleteEvent += delegate { Application.Quit(); };

            Button bt = new Button("Create button");
            bt.Clicked += delegate (object o, EventArgs args)
            {
                addButton(80,80); //does not work
            };


            _fix.Put(bt, 20, 30);

            Add(_fix);
            ShowAll();
        }

        public void addButton(int x, int y)
        {
            Button bt = new Button("DYNAMIC");
            _fix.Put(bt, x, y);
        }
    }

您的addButton缺少对Add()的调用。

将您的方法更改为此

 public void addButton(int x, int y)
    {
        Button bt = new Button("rolund");
        _fix.Put(bt, x, y);
        bt.show();
    }
我不需要调用“添加”,因为我将按钮添加到“固定”容器中,该容器已添加到窗口本身。。。