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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 對話框 > 原文: [http://zetcode.com/gui/vbgtk/dialogs/](http://zetcode.com/gui/vbgtk/dialogs/) 在 Visual Basic GTK# 編程教程的這一部分中,我們將介紹對話框。 對話框窗口或對話框是大多數現代 GUI 應用必不可少的部分。 對話被定義為兩個或更多人之間的對話。 在計算機應用中,對話框是一個窗口,用于與應用“對話”。 對話框用于輸入數據,修改數據,更改應用設置等。對話框是用戶與計算機程序之間進行通信的重要手段。 ## `MessageDialog` 消息對話框是方便的對話框,可向應用的用戶提供消息。 該消息包含文本和圖像數據。 ```vb ' ZetCode Mono Visual Basic GTK# tutorial ' ' This program shows message dialogs. ' ' author jan bodnar ' last modified May 2009 ' website www.zetcode.com Imports Gtk Public Class GtkVBApp Inherits Window Public Sub New MyBase.New("Message dialogs") Me.InitUI Me.SetDefaultSize(250, 100) Me.SetPosition(WindowPosition.Center) AddHandler Me.DeleteEvent, AddressOf Me.OnDelete Me.ShowAll End Sub Private Sub InitUI Dim table As New Table(2, 2, True) Dim info As New Button("Information") Dim warn As New Button("Warning") Dim ques As New Button("Question") Dim erro As New Button("Error") AddHandler info.Clicked, AddressOf Me.OnInfo AddHandler warn.Clicked, AddressOf Me.OnWarning AddHandler ques.Clicked, AddressOf Me.OnQuestion AddHandler erro.Clicked, AddressOf Me.OnError 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) Me.Add(table) End Sub Private Sub OnInfo(ByVal sender As Object, ByVal args As EventArgs) Dim md As MessageDialog = New MessageDialog(Me, _ DialogFlags.DestroyWithParent, MessageType.Info, _ ButtonsType.Close, "Download completed") md.Run md.Destroy End Sub Private Sub OnWarning(ByVal sender As Object, ByVal args As EventArgs) Dim md As MessageDialog = New MessageDialog(Me, _ DialogFlags.DestroyWithParent, MessageType.Warning, _ ButtonsType.Close, "Unallowed operation") md.Run md.Destroy End Sub Private Sub OnQuestion(ByVal sender As Object, ByVal args As EventArgs) Dim md As MessageDialog = New MessageDialog(Me, _ DialogFlags.DestroyWithParent, MessageType.Question, _ ButtonsType.Close, "Are you sure to quit?") md.Run md.Destroy End Sub Private Sub OnError(ByVal sender As Object, ByVal args As EventArgs) Dim md As MessageDialog = New MessageDialog(Me, _ DialogFlags.DestroyWithParent, MessageType.Error, _ ButtonsType.Close, "Error loading file") md.Run md.Destroy End Sub Private Sub OnDelete(ByVal sender As Object, _ ByVal args As DeleteEventArgs) Application.Quit End Sub Public Shared Sub Main Application.Init Dim app As New GtkVBApp Application.Run End Sub End Class ``` 在我們的示例中,我們將顯示四種消息對話框。 信息,警告,問題和錯誤消息對話框。 ```vb Dim info As New Button("Information") Dim warn As New Button("Warning") Dim ques As New Button("Question") Dim erro As New Button("Error") ``` 我們有四個按鈕。 這些按鈕中的每個按鈕都會顯示不同類型的消息對話框。 ```vb Private Sub OnInfo(ByVal sender As Object, ByVal args As EventArgs) Dim md As MessageDialog = New MessageDialog(Me, _ DialogFlags.DestroyWithParent, MessageType.Info, _ ButtonsType.Close, "Download completed") md.Run md.Destroy End Sub ``` 如果單擊信息按鈕,將顯示“信息”對話框。 `MessageType.Info`指定對話框的類型。 `ButtonsType.Close`指定要在對話框中顯示的按鈕。 最后一個參數是已分發的消息。 該對話框使用`Run`方法顯示。 程序員還必須調用`Destroy`或`Hide`方法。 ![Information message dialog](https://img.kancloud.cn/74/21/742112a7f15176073658fc9c6c6c5c62_223x158.jpg) ![Warning message dialog](https://img.kancloud.cn/fe/a5/fea5b886f9d1da77913bf4bbda804a4e_221x158.jpg) ![Question message dialog](https://img.kancloud.cn/bc/ec/bcec676671a0a8979f3ae54bac7be684_222x158.jpg) ![Error message dialog](https://img.kancloud.cn/9b/6d/9b6dc5423651e5cf580c077d84d08dcb_195x158.jpg) ## `AboutDialog` `AboutDialog`顯示有關應用的信息。 `AboutDialog`可以顯示徽標,應用名稱,版本,版權,網站或許可證信息。 也有可能對作者,文檔撰寫者,翻譯者和藝術家予以贊揚。 ```vb ' ZetCode Mono Visual Basic GTK# tutorial ' ' This program shows the about ' dialog ' ' author jan bodnar ' last modified May 2009 ' website www.zetcode.com Imports Gtk Public Class GtkVBApp Inherits Window Public Sub New MyBase.New("About dialog") Me.InitUI Me.SetDefaultSize(350, 300) Me.SetPosition(WindowPosition.Center) AddHandler Me.DeleteEvent, AddressOf Me.OnDelete Me.ShowAll End Sub Private Sub InitUI Dim button As New Button("About") AddHandler button.Clicked, AddressOf Me.ShowDialog Dim fixed As New Fixed fixed.Put(button, 20, 20) Me.Add(fixed) End Sub Private Sub ShowDialog(ByVal sender As Object, _ ByVal args As EventArgs) Dim about As 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 End Sub Sub OnDelete(ByVal sender As Object, _ ByVal args As DeleteEventArgs) Application.Quit End Sub Public Shared Sub Main Application.Init Dim app As New GtkVBApp Application.Run End Sub End Class ``` 該代碼示例使用具有某些功能的`AboutDialog`。 ```vb Dim about As New AboutDialog ``` 我們創建一個`AboutDialog`。 ```vb Dim about As New AboutDialog about.ProgramName = "Battery" about.Version = "0.1" about.Copyright = "(c) Jan Bodnar" ``` 通過設置對話框的屬性,我們指定名稱,版本和版權。 ```vb about.Logo = New Gdk.Pixbuf("battery.png") ``` 此行創建徽標。 ![AboutDialog](https://img.kancloud.cn/29/dd/29ddfd9ac825c1f7a43e92c6e75ec5c0_305x230.jpg) 圖:`AboutDialog` ## `FontSelectionDialog` `FontSelectionDialog`是用于選擇字體的對話框。 它通常用于進行一些文本編輯或格式化的應用中。 ```vb ' ZetCode Mono Visual Basic GTK# tutorial ' ' This program shows the FontSelectionDialog ' ' author jan bodnar ' last modified May 2009 ' website www.zetcode.com Imports Gtk Public Class GtkVBApp Inherits Window Dim label As Label Public Sub New MyBase.New("Font dialog") Me.InitUI Me.SetDefaultSize(350, 300) Me.SetPosition(WindowPosition.Center) AddHandler Me.DeleteEvent, AddressOf Me.OnDelete Me.ShowAll End Sub Private Sub InitUI label = New Label("The only victory over love is flight.") Dim button As New Button("Select font") AddHandler button.Clicked, AddressOf Me.ShowDialog Dim fixed As New Fixed fixed.Put(button, 100, 30) fixed.Put(label, 30, 90) Me.Add(fixed) End Sub Private Sub ShowDialog(ByVal sender As Object, _ ByVal args As EventArgs) Dim fdia As New FontSelectionDialog("Select font name") AddHandler fdia.Response, AddressOf Me.SelectFont fdia.Run fdia.Destroy End Sub Private Sub SelectFont(ByVal sender As Object, _ ByVal args As ResponseArgs) If args.ResponseId = ResponseType.Ok Dim fontdesc As Pango.FontDescription = _ Pango.FontDescription.FromString(sender.FontName) label.ModifyFont(fontdesc) End If End Sub Sub OnDelete(ByVal sender As Object, _ ByVal args As DeleteEventArgs) Application.Quit End Sub Public Shared Sub Main Application.Init Dim app As New GtkVBApp Application.Run End Sub End Class ``` 在代碼示例中,我們有一個按鈕和一個標簽。 單擊按鈕顯示`FontSelectionDialog`。 ```vb Dim fdia As New FontSelectionDialog("Select font name") ``` 我們創建`FontSelectionDialog`。 ```vb If args.ResponseId = ResponseType.Ok Dim fontdesc As Pango.FontDescription = _ Pango.FontDescription.FromString(sender.FontName) label.ModifyFont(fontdesc) End If ``` 如果單擊“確定”按鈕,則標簽小部件的字體將更改為我們在對話框中選擇的字體。 ![FontSelectionDialog](https://img.kancloud.cn/f7/95/f79554e69b3d6a0d0b3ce756c3a2c9e1_460x363.jpg) 圖:`FontSelectionDialog` ## `ColorSelectionDialog` `ColorSelectionDialog`是用于選擇顏色的對話框。 ```vb ' ZetCode Mono Visual Basic GTK# tutorial ' ' This program shows the ColorSelectionDialog ' ' author jan bodnar ' last modified May 2009 ' website www.zetcode.com Imports Gtk Public Class GtkVBApp Inherits Window Dim label As Label Public Sub New MyBase.New("Color dialog") Me.InitUI Me.SetDefaultSize(350, 300) Me.SetPosition(WindowPosition.Center) AddHandler Me.DeleteEvent, AddressOf Me.OnDelete Me.ShowAll End Sub Private Sub InitUI label = New Label("The only victory over love is flight.") Dim button As New Button("Select color") AddHandler button.Clicked, AddressOf Me.ShowDialog Dim fixed As New Fixed fixed.Put(button, 100, 30) fixed.Put(label, 30, 90) Me.Add(fixed) End Sub Private Sub ShowDialog(ByVal sender As Object, _ ByVal args As EventArgs) Dim cdia As New ColorSelectionDialog("Select color") AddHandler cdia.Response, AddressOf Me.SelectColor cdia.Run cdia.Destroy End Sub Private Sub SelectColor(ByVal sender As Object, _ ByVal args As ResponseArgs) If args.ResponseId = ResponseType.Ok label.ModifyFg(StateType.Normal, _ sender.ColorSelection.CurrentColor) End If End Sub Sub OnDelete(ByVal sender As Object, _ ByVal args As DeleteEventArgs) Application.Quit End Sub Public Shared Sub Main Application.Init Dim app As New GtkVBApp Application.Run End Sub End Class ``` 該示例與上一個示例非常相似。 這次我們更改標簽的顏色。 ```vb Dim cdia As New ColorSelectionDialog("Select color") ``` 我們創建`ColorSelectionDialog`。 ```vb If args.ResponseId = ResponseType.Ok label.ModifyFg(StateType.Normal, _ sender.ColorSelection.CurrentColor) End If ``` 如果用戶按下 OK,我們將獲得顏色值并修改標簽的顏色。 ![ColorSelectionDialog](https://img.kancloud.cn/e9/09/e909ae6c18d6c96e69d89ef449aeee91_531x314.jpg) 圖:顏色 electionDialog 在 Visual Basic 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>

                              哎呀哎呀视频在线观看