GTK 中的 MessageBox 从未显示

我在 OSX 上使用 VS Code,并尝试在我的按钮按下事件中向用户显示一个对话框。下面的代码是我所拥有的,但是当按下按钮时,对话框永远不会显示。


    public static void Main(string[] args)

    {

        Application.Init();


        MainWindow win = new MainWindow();


        Button btnClick = new Button("Button");

        win.Add(btnClick);


        btnClick.ButtonPressEvent += new ButtonPressEventHandler(ButtonPressHandler);

        btnClick.Visible = true;

        win.Show();

        Application.Run();


    }


    private static void ButtonPressHandler(object obj, ButtonPressEventArgs args)

    {

        MessageDialog md = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, "You pressed the button!");

        md.Run();

        md.Destroy();

    }


慕仙森
浏览 65回答 1
1回答

墨色风雨

我认为您需要 btnClick.Clicked 而不是 btnClick.ButtonPressEvent。甚至似乎没有 ButtonPressEvent 成员。请参阅http://docs.go-mono.com/?link=T%3aGtk.Button
打开App,查看更多内容
随时随地看视频慕课网APP