簡體   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