<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # GTK# 中的對話框 > 原文: [http://zetcode.com/gui/gtksharp/dialogs/](http://zetcode.com/gui/gtksharp/dialogs/) 在 GTK# 編程教程的這一部分中,我們將介紹對話框。 對話框窗口或對話框是大多數現代 GUI 應用必不可少的部分。 對話被定義為兩個或更多人之間的對話。 在計算機應用中,對話框是一個窗口,用于與應用“對話”。 對話框用于輸入數據,修改數據,更改應用設置等。對話框是用戶與計算機程序之間進行通信的重要手段。 ## `MessageDialog` 消息對話框是方便的對話框,可向應用的用戶提供消息。 該消息包含文本和圖像數據。 `messages.cs` ```cs using Gtk; using System; class SharpApp : Window { public SharpApp() : base("Messages") { SetDefaultSize(250, 100); SetPosition(WindowPosition.Center); DeleteEvent += delegate { Application.Quit(); }; Table table = new Table(2, 2, true); Button info = new Button("Information"); Button warn = new Button("Warning"); Button ques = new Button("Question"); Button erro = new Button("Error"); info.Clicked += delegate { MessageDialog md = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, "Download completed"); md.Run(); md.Destroy(); }; warn.Clicked += delegate { MessageDialog md = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Warning, ButtonsType.Close, "Unallowed operation"); md.Run(); md.Destroy(); }; ques.Clicked += delegate { MessageDialog md = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.Close, "Are you sure to quit?"); md.Run(); md.Destroy(); }; erro.Clicked += delegate { MessageDialog md = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Close, "Error loading file"); md.Run(); md.Destroy(); }; table.Attach(info, 0, 1, 0, 1); table.Attach(warn, 1, 2, 0, 1); table.Attach(ques, 0, 1, 1, 2); table.Attach(erro, 1, 2, 1, 2); Add(table); ShowAll(); } public static void Main() { Application.Init(); new SharpApp(); Application.Run(); } } ``` 在我們的示例中,我們將顯示四種消息對話框。 信息,警告,問題和錯誤消息對話框。 ```cs Button info = new Button("Information"); Button warn = new Button("Warning"); Button ques = new Button("Question"); Button erro = new Button("Error"); ``` 我們有四個按鈕。 這些按鈕中的每個按鈕都會顯示不同類型的消息對話框。 ```cs info.Clicked += delegate { MessageDialog md = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, "Download completed"); md.Run(); md.Destroy(); }; ``` 如果單擊信息按鈕,將顯示“信息”對話框。 `MessageType.Info`指定對話框的類型。 `ButtonsType.Close`指定要在對話框中顯示的按鈕。 最后一個參數是顯示的消息。 該對話框使用`Run()`方法顯示。 程序員還必須調用`Destroy()`或`Hide()`方法。 ![Information message dialog](https://img.kancloud.cn/0b/57/0b57b208d8ef4ccc80d69f8a78421139_226x158.jpg) ![Warning message dialog](https://img.kancloud.cn/52/87/5287cc6bda2b8e553ee222b6658b02fd_222x158.jpg) ![Question message dialog](https://img.kancloud.cn/ef/8f/ef8ffb909aeca6598f8c227f80205105_225x158.jpg) ![Error message dialog](https://img.kancloud.cn/74/eb/74eb42cc7148a2ca7510b9722adf555b_195x158.jpg) ## `AboutDialog` `AboutDialog`顯示有關應用的信息。 `AboutDialog`可以顯示徽標,應用名稱,版本,版權,網站或許可證信息。 也有可能對作者,文檔撰寫者,翻譯者和藝術家予以贊揚。 `aboutdialog.cs` ```cs using Gtk; using System; class SharpApp : Window { public SharpApp() : base("About") { SetDefaultSize(300, 270); SetPosition(WindowPosition.Center); DeleteEvent += delegate { Application.Quit(); } ; Button button = new Button("About"); button.Clicked += OnClicked; Fixed fix = new Fixed(); fix.Put(button, 20, 20); Add(fix); ShowAll(); } void OnClicked(object sender, EventArgs args) { AboutDialog about = new AboutDialog(); about.ProgramName = "Battery"; about.Version = "0.1"; about.Copyright = "(c) Jan Bodnar"; about.Comments = @"Battery is a simple tool for battery checking"; about.Website = "http://www.zetcode.com"; about.Logo = new Gdk.Pixbuf("battery.png"); about.Run(); about.Destroy(); } public static void Main() { Application.Init(); new SharpApp(); Application.Run(); } } ``` 該代碼示例使用具有某些功能的`AboutDialog`。 ```cs AboutDialog about = new AboutDialog(); ``` 我們創建一個`AboutDialog`。 ```cs about.ProgramName = "Battery"; about.Version = "0.1"; about.Copyright = "(c) Jan Bodnar"; ``` 通過設置對話框的屬性,我們指定名稱,版本和版權。 ```cs about.Logo = new Gdk.Pixbuf("battery.png"); ``` 此行創建徽標。 ![AboutDialog](https://img.kancloud.cn/a6/c6/a6c64729ade9b2509adff2e1b597a10c_204x255.jpg) 圖:`AboutDialog` ## `FontSelectionDialog` `FontSelectionDialog`是用于選擇字體的對話框。 它通常用于進行一些文本編輯或格式化的應用中。 `fontdialog.cs` ```cs using Gtk; using System; class SharpApp : Window { Label label; public SharpApp() : base("Font Selection Dialog") { SetDefaultSize(300, 220); SetPosition(WindowPosition.Center); DeleteEvent += delegate { Application.Quit(); } ; label = new Label("The only victory over love is flight."); Button button = new Button("Select font"); button.Clicked += OnClicked; Fixed fix = new Fixed(); fix.Put(button, 100, 30); fix.Put(label, 30, 90); Add(fix); ShowAll(); } void OnClicked(object sender, EventArgs args) { FontSelectionDialog fdia = new FontSelectionDialog("Select font name"); fdia.Response += delegate (object o, ResponseArgs resp) { if (resp.ResponseId == ResponseType.Ok) { Pango.FontDescription fontdesc = Pango.FontDescription.FromString(fdia.FontName); label.ModifyFont(fontdesc); } }; fdia.Run(); fdia.Destroy(); } public static void Main() { Application.Init(); new SharpApp(); Application.Run(); } } ``` 在代碼示例中,我們有一個按鈕和一個標簽。 單擊按鈕顯示`FontSelectionDialog`。 ```cs FontSelectionDialog fdia = new FontSelectionDialog("Select font name"); ``` 我們創建了`FontSelectionDialog.` ```cs fdia.Response += delegate (object o, ResponseArgs resp) { if (resp.ResponseId == ResponseType.Ok) { Pango.FontDescription fontdesc = Pango.FontDescription.FromString(fdia.FontName); label.ModifyFont(fontdesc); } }; ``` 如果單擊“確定”按鈕,則標簽小部件的字體將更改為我們在對話框中選擇的字體。 ![FontSelectionDialog](https://img.kancloud.cn/f8/b6/f8b6a45fb73c0f82a1d973343d9c9ed1_460x369.jpg) 圖:`FontSelectionDialog` ## `ColorSelectionDialog` `ColorSelectionDialog`是用于選擇顏色的對話框。 `colordialog.cs` ```cs using Gtk; using System; class SharpApp : Window { Label label; public SharpApp() : base("Color Dialog") { SetDefaultSize(300, 220); SetPosition(WindowPosition.Center); DeleteEvent += delegate { Application.Quit(); } ; label = new Label("The only victory over love is flight."); Button button = new Button("Select color"); button.Clicked += OnClicked; Fixed fix = new Fixed(); fix.Put(button, 100, 30); fix.Put(label, 30, 90); Add(fix); ShowAll(); } void OnClicked(object sender, EventArgs args) { ColorSelectionDialog cdia = new ColorSelectionDialog("Select color"); cdia.Response += delegate (object o, ResponseArgs resp) { if (resp.ResponseId == ResponseType.Ok) { label.ModifyFg(StateType.Normal, cdia.ColorSelection.CurrentColor); } }; cdia.Run(); cdia.Destroy(); } public static void Main() { Application.Init(); new SharpApp(); Application.Run(); } } ``` 該示例與上一個示例非常相似。 這次我們更改標簽的顏色。 ```cs ColorSelectionDialog cdia = new ColorSelectionDialog("Select color"); ``` 我們創建`ColorSelectionDialog`。 ```cs cdia.Response += delegate (object o, ResponseArgs resp) { if (resp.ResponseId == ResponseType.Ok) { label.ModifyFg(StateType.Normal, cdia.ColorSelection.CurrentColor); } }; ``` 如果用戶按下 OK,我們將獲得顏色并修改標簽的顏色。 ![ColorSelectionDialog](https://img.kancloud.cn/d4/1f/d41fd1b07ac5a391a6bafaa7322f5f95_539x314.jpg) 圖:顏色 electionDialog 在 GTK# 教程的這一部分中,我們討論了對話框。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看