<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國際加速解決方案。 廣告
                {% raw %} # Qyoto 對話框 > 原文: [http://zetcode.com/gui/csharpqyoto/dialogs/](http://zetcode.com/gui/csharpqyoto/dialogs/) 在 Qyoto C# 編程教程的這一部分中,我們將使用對話框。 對話框窗口或對話框是大多數現代 GUI 應用必不可少的部分。 對話被定義為兩個或更多人之間的對話。 在計算機應用中,對話框是一個窗口,用于與應用“對話”。 對話框用于輸入數據,修改數據,更改應用設置等。對話框是用戶與計算機程序之間進行通信的重要手段。 ## `MessageDialog` 消息框是方便的對話框,可向應用的用戶提供消息。 該消息由文本和圖像數據組成。 ```cs using System; using QtCore; using QtGui; /** * ZetCode Qyoto C# tutorial * * This program shows * QMessageBox dialogs * * @author Jan Bodnar * website zetcode.com * last modified October 2012 */ public class QyotoApp : QWidget { public QyotoApp() { WindowTitle = "Message boxes"; InitUI(); Resize(220, 90); Move(300, 300); Show(); } void InitUI() { QGridLayout grid = new QGridLayout(this); grid.Spacing = 2; QPushButton error = new QPushButton("Error", this); QPushButton warni = new QPushButton("Warning", this); QPushButton quest = new QPushButton("Question", this); QPushButton infor = new QPushButton("Information", this); QPushButton about = new QPushButton("About", this); grid.AddWidget(error, 0, 0); grid.AddWidget(warni, 0, 1); grid.AddWidget(quest, 1, 0); grid.AddWidget(infor, 1, 1); grid.AddWidget(about, 2, 0); error.Clicked += ShowDialog; warni.Clicked += ShowDialog; quest.Clicked += ShowDialog; infor.Clicked += ShowDialog; about.Clicked += ShowDialog; } [Q_SLOT] void ShowDialog() { QPushButton btn = (QPushButton) Sender(); if ("Error".Equals(btn.Text)) { QMessageBox.Critical(this, "Error", "Error loading file!"); } else if ("Warning".Equals(btn.Text)) { QMessageBox.Warning(this, "Warning", "Operation not permitted!"); } else if ("Question".Equals(btn.Text)) { QMessageBox.Question(this, "Question", "Are you sure to quit?"); } else if ("Information".Equals(btn.Text)) { QMessageBox.Information(this, "Information", "Download completed."); } else if ("About".Equals(btn.Text)) { QMessageBox.About(this, "About", "ZetCode Qyoto C# tutorial."); } } [STAThread] public static int Main(String[] args) { new QApplication(args); new QyotoApp(); return QApplication.Exec(); } } ``` 我們使用`GridLayout`管理器來設置五個按鈕的網格。 每個按鈕顯示一個不同的消息框。 ```cs QPushButton button = (QPushButton) Sender(); ``` 在這里,我們確定哪個按鈕稱為`ShowDialog()`方法。 ```cs if ("Error".Equals(btn.Text)) { QMessageBox.Critical(this, "Error", "Error loading file!"); } ``` 如果按下錯誤按鈕,則會顯示錯誤對話框。 我們使用`QMessageBox`類的靜態方法來顯示消息框。 ![Information message dialog](https://img.kancloud.cn/d4/ae/d4ae11818b9f2af162efe0a4cc74ea87_208x117.jpg) ![Warning message dialog](https://img.kancloud.cn/cf/8f/cf8f49792a0e9836b2eb414e7081b52f_229x117.jpg) ![Question message dialog](https://img.kancloud.cn/4c/be/4cbef95bdc9781de9d958043c3bc59a7_203x117.jpg) ![Error message dialog](https://img.kancloud.cn/07/fd/07fd73102ecd163de8426feb6ba47af5_182x117.jpg) ![About message dialog](https://img.kancloud.cn/02/44/0244b1f335a79f6a5aec215283844569_198x108.jpg) ## `QInputDialog` `QInputDialog`類提供了一個簡單的便捷對話框,可從用戶那里獲取單個值。 輸入值可以是字符串,數字或列表中的。 必須設置標簽以告知用戶他們應該輸入什么。 ```cs using System; using QtCore; using QtGui; /** * ZetCode Qyoto C# tutorial * * This program shows an input * dialog. * * @author Jan Bodnar * website zetcode.com * last modified October 2012 */ public class QyotoApp : QWidget { QLineEdit edit; public QyotoApp() { WindowTitle = "QInputDialog"; InitUI(); Resize(300, 150); Move(300, 300); Show(); } void InitUI() { QPushButton show = new QPushButton("Dialog", this); show.Clicked += ShowDialog; show.FocusPolicy = Qt.FocusPolicy.NoFocus; show.Move(20, 20); edit = new QLineEdit(this); edit.Move(130, 22); } [Q_SLOT] void ShowDialog() { String text = QInputDialog.GetText( this, "Input Dialog", "Enter your name"); if (text!=null && text.Trim() != String.Empty) { edit.Text = text; } } [STAThread] public static int Main(String[] args) { new QApplication(args); new QyotoApp(); return QApplication.Exec(); } } ``` 在代碼示例中,我們有一個按鈕和一行編輯。 該按鈕顯示一個輸入對話框。 我們得到一些文本,文本顯示在行編輯小部件中。 ```cs String text = QInputDialog.GetText( this, "Input Dialog", "Enter your name"); ``` `GetText()`靜態方法創建輸入對話框。 對話框中的文本存儲在`text`變量中。 ```cs if (text!=null && text.Trim() != String.Empty) { edit.Text = text; } ``` 在更新行編輯之前,請確保`text`變量不為`null`且不為空,并且不僅由空格組成。 ![Input dialog](https://img.kancloud.cn/e2/ad/e2adf580f28f8532fe72af6305cc3d67_206x135.jpg) 圖:輸入對話框 ## `QColorDialog` `QColorDialog`類提供用于指定顏色的對話框小部件。 顏色對話框的功能是允許用戶選擇顏色。 ```cs using System; using QtCore; using QtGui; /** * ZetCode Qyoto C# tutorial * * In this program, we use the * QColorDialog to change the colour * of a label text. * * @author Jan Bodnar * website zetcode.com * last modified October 2012 */ public class QyotoApp : QWidget { QLabel label; public QyotoApp() : base() { WindowTitle = "QColorDialog"; InitUI(); Resize(250, 200); Move(300, 300); Show(); } void InitUI() { label = new QLabel("ZetCode Qyoto C# tutorial", this); QVBoxLayout vbox = new QVBoxLayout(this); label.Alignment = AlignmentFlag.AlignCenter; vbox.AddWidget(label); } protected override void OnMousePressEvent(QMouseEvent arg1) { QColor col = QColorDialog.GetColor(); if (!col.IsValid()) return; String style = String.Format("QWidget {{ color: {0} }}", col.Name()); label.StyleSheet = style; } [STAThread] public static int Main(String[] args) { new QApplication(args); new QyotoApp(); return QApplication.Exec(); } } ``` 我們在窗口中心顯示一些文本。 通過單擊窗口區域,我們顯示一個顏色對話框。 我們將文本前景色更改為從對話框中選擇的顏色。 ```cs protected override void OnMousePressEvent(QMouseEvent arg1) { ... } ``` 為了接收我們窗口的鼠標按下事件,我們必須重寫`MousePressEvent()`方法。 ```cs QColor col = QColorDialog.GetColor(); ``` 正在創建`QColorDialog`。 所選顏色存儲在`col`變量中。 ```cs if (!color.IsValid()) return; ``` 當按下取消按鈕時,我們什么也不做。 ```cs String style = String.Format("QWidget {{ color: {0} }}", color.Name()); label.SetStyleSheet(style); ``` 在這里,我們更新標簽文本的前景色。 ![QColorDialog](https://img.kancloud.cn/ca/7b/ca7bc14ae45e67d8358252d27471dafa_350x270.jpg) 圖:`QColorDialog` ## `QFontDialog` `QFontDialog`類提供用于選擇字體的對話框小部件。 ```cs using System; using QtCore; using QtGui; /** * ZetCode Qyoto C# tutorial * * In this program, we use the * QFontDialog to change the font * of a label text. * * @author Jan Bodnar * website zetcode.com * last modified October 2012 */ public class QyotoApp : QWidget { QLabel label; public QyotoApp() : base() { WindowTitle = "QFontDialog"; InitUI(); Resize(250, 200); Move(300, 300); Show(); } void InitUI() { label = new QLabel("ZetCode Qyoto C# tutorial", this); QVBoxLayout vbox = new QVBoxLayout(this); label.Alignment = AlignmentFlag.AlignCenter; vbox.AddWidget(label); } protected override void OnMousePressEvent(QMouseEvent arg1) { bool ok = true; QFont font = QFontDialog.GetFont(ref ok); if (!ok) return; label.Font = font; } [STAThread] public static int Main(String[] args) { new QApplication(args); new QyotoApp(); return QApplication.Exec(); } } ``` 此示例與上一個示例相似。 這次,我們更改文本的字體。 ```cs QFont font = QFontDialog.GetFont(ref ok); ``` 正在創建`QFontDialog`。 當我們按下對話框的 OK 按鈕時,將設置`boolean ok`變量。 ```cs if (!ok) return; ``` 如果不按“確定”按鈕,我們什么也不做。 ```cs label.Font = font; ``` `font`字段存儲所選字體。 我們將標簽的字體更新為新選擇的字體。 ![QFontDialog](https://img.kancloud.cn/40/3e/403ef54cd8fe7d45bf6baaea8d6ecc72_350x266.jpg) 圖:`QFontDialog` 在 Qyoto C# 教程的這一部分中,我們使用了對話框窗口。 {% endraw %}
                  <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>

                              哎呀哎呀视频在线观看