繁体   English   中英

如何使我的GTK#程序退出?

[英]How Do I make My GTK# program quit?

我开始学习GTK#,并编写了第一个GUI程序。 当我通过终端运行它时,当我单击右上角的X时,它没有退出程序。 当我看着任务管理器时,我再次运行了它,实际上它并没有退出。 我必须手动杀死它。 我需要特殊的代码才能退出吗? 我当前的代码是

using System;
using Gtk;

public class GtkHelloWorld {

  public static void Main() {
    Application.Init();

    //Create the Window
    Window myWin = new Window("My first GTK# Application! ");
    myWin.Resize(200,200);

    //Create a label and put some text in it.     
    Label myLabel = new Label();
    myLabel.Text = "Hello World!!!!";

    //Add the label to the form     
    myWin.Add(myLabel);

    //Show Everything     
    myWin.ShowAll();

    Application.Run();   
  }
}

我针对Mono的版本4进行了编译,因此我必须使用mono --runtime=v4.0 /path/to/file.exe在终端中运行它

要退出,您需要调用Application.Quit (); 通常,人们执行此操作的方式是通过如下方式连接到窗口的DeleteEvent:

myWin.DeleteEvent += delegate (sender, args) {
    Application.Quit ();
};

暂无
暂无

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

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