简体   繁体   English

从未显示的GTK中的MessageBox

[英]MessageBox In GTK Never Shown

I am using VS Code on OSX and am trying to on my button press event, display a dialog to user. 我在OSX上使用VS Code并尝试按下我的按钮事件,向用户显示一个对话框。 The code below is what I have, but when the button is pressed, the dialog is never shown. 下面的代码就是我所拥有的,但是当按下该按钮时,对话框永远不会显示。

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

I think you want btnClick.Clicked rather than btnClick.ButtonPressEvent. 我想你想要btnClick.Clicked而不是btnClick.ButtonPressEvent。 There doesn't even seem to be a ButtonPressEvent member. 似乎没有ButtonPressEvent成员。 See http://docs.go-mono.com/?link=T%3aGtk.Button 请参阅http://docs.go-mono.com/?link=T%3aGtk.Button

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM