彈出對(duì)話框
Flyout Dialog提供了類似于彈出內(nèi)容容器的功能,允許您在應(yīng)用程序UI管理器組件的WindowsUI視圖中創(chuàng)建Windows 10風(fēng)格的彈出消息,但是Flyout Dialog允許在應(yīng)用程序中實(shí)現(xiàn)此功能,而無需使用任何其他組件。要顯示彈出式消息框或彈出窗口,只需在代碼中調(diào)用FlyoutDialog.Show方法。
C#:
DevExpress.XtraBars.Docking2010.Customization.FlyoutDialog.Show(. . .);
點(diǎn)擊復(fù)制
VB.NET:
DevExpress.XtraBars.Docking2010.Customization.FlyoutDialog.Show(. . .)
點(diǎn)擊復(fù)制
Show方法有多個(gè)重載。根據(jù)選擇的重載,必須將所有者、控件、彈出動(dòng)作、彈出屬性和謂詞作為參數(shù)傳遞。
- Owner——將擁有顯示的彈出式消息框或彈出框的表,使用此關(guān)鍵字可將當(dāng)前表單設(shè)置為彈出框的父表單。
- Control——在彈出框中顯示的控件或UserControl對(duì)象,下圖展示了一個(gè)空白的彈出式窗口,其中包含一個(gè)WindowsUIButtonPanel。
FlyoutAction ——一個(gè)FlyoutAction對(duì)象,它包含標(biāo)題、描述、圖像和一組在這個(gè)彈出框中顯示的按鈕。下圖展示了一個(gè)示例。
下面的代碼創(chuàng)建了一個(gè)帶有自定義標(biāo)題、描述和兩個(gè)Flyout命令(' Close '和' Cancel ')的Flyout Action,它們具有特定的 DialogResult 值。
C#:
DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutAction action = new DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutAction() { Caption = "Confirm", Description = "Close the application?" }; DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutCommand command1 = new DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutCommand() { Text = "Close", Result = System.Windows.Forms.DialogResult.Yes }; DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutCommand command2 = new DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutCommand() { Text = "Cancel", Result = System.Windows.Forms.DialogResult.No }; action.Commands.Add(command1); action.Commands.Add(command2);
點(diǎn)擊復(fù)制
VB.NET:
Dim command1 As New DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutCommand() With { _ .Text = "Close", _ .Result = System.Windows.Forms.DialogResult.Yes _ } Dim command2 As New DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutCommand() With { _ .Text = "Cancel", _ .Result = System.Windows.Forms.DialogResult.No _ } action.Commands.Add(command1) action.Commands.Add(command2)
點(diǎn)擊復(fù)制
提示:如果將Control 和FlyoutAction傳遞給FlyoutDialog.Show方法,F(xiàn)lyoutAction的標(biāo)題和按鈕將被顯示,而描述和圖像將被隱藏。
Flyout Properties——一個(gè) DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutProperties對(duì)象,用于存儲(chǔ)顯示的彈出框的高級(jí)屬性。例如,下面代碼中的Style屬性允許您選擇彈出樣式(在整個(gè)表單中顯示的消息框或彈出窗口),ButtonSize屬性設(shè)置自定義動(dòng)作按鈕的大小。
C#:
FlyoutProperties properties = new FlyoutProperties(); properties.ButtonSize = new Size(100, 40); properties.Style = FlyoutStyle.MessageBox;
點(diǎn)擊復(fù)制
VB.NET:
Dim properties As New FlyoutProperties() properties.ButtonSize = New Size(100, 40) properties.Style = FlyoutStyle.MessageBox
點(diǎn)擊復(fù)制
Predicate——引用一個(gè)布爾函數(shù)的謂詞,該函數(shù)接受一個(gè)DialogResult 值作為參數(shù)。該函數(shù)根據(jù)彈出框的輸出DialogResult 指定是否可以關(guān)閉彈出框,謂詞強(qiáng)制最終用戶單擊彈出按鈕,從而確保彈出不會(huì)通過任何其他方式關(guān)閉(例如,按“Esc”按鈕)。下面的代碼演示了一個(gè)示例。
C#:
Predicate<DialogResult> predicate = canCloseFunc; private static bool canCloseFunc(DialogResult parameter) { return parameter != DialogResult.Cancel; }
點(diǎn)擊復(fù)制
VB.NET:
Private predicate As Predicate(Of DialogResult) = AddressOf canCloseFunc Private Shared Function canCloseFunc(ByVal parameter As DialogResult) As Boolean Return parameter <> DialogResult.Cancel End Function
點(diǎn)擊復(fù)制
Show方法返回 DialogResult枚舉器值,該值允許檢查單擊了哪個(gè)FlyoutCommand。使用這個(gè)和上面的信息,您可以在父表單關(guān)閉時(shí)顯示一個(gè)彈出對(duì)話框,如下面的代碼所示。這段代碼顯示了一個(gè)帶有兩個(gè)按鈕的彈出消息框,使用的謂詞確保flyout只有在終端用戶在“Close”和“Cance”選項(xiàng)之間選擇后才會(huì)關(guān)閉。
C#:
private static bool canCloseFunc(DialogResult parameter) { return parameter != DialogResult.Cancel; } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutAction action = new DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutAction() { Caption = "Confirm", Description = "Close the application?" }; Predicate<DialogResult> predicate = canCloseFunc; DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutCommand command1 = new DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutCommand() { Text = "Close", Result = System.Windows.Forms.DialogResult.Yes }; DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutCommand command2 = new DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutCommand() { Text = "Cancel", Result = System.Windows.Forms.DialogResult.No }; action.Commands.Add(command1); action.Commands.Add(command2); FlyoutProperties properties = new FlyoutProperties(); properties.ButtonSize = new Size(100, 40); properties.Style = FlyoutStyle.MessageBox; if (FlyoutDialog.Show(this, action, properties, predicate) == System.Windows.Forms.DialogResult.Yes) e.Cancel = false; else e.Cancel = true; }
點(diǎn)擊復(fù)制
VB.NET:
Private Shared Function canCloseFunc(ByVal parameter As DialogResult) As Boolean Return parameter IsNot DialogResult.Cancel End Function Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Dim action As New DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutAction() With {.Caption = "Confirm", .Description = "Close the application?"} Dim predicate As Predicate(Of DialogResult) = AddressOf canCloseFunc Dim command1 As New DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutCommand() With {.Text = "Close", .Result = System.Windows.Forms.DialogResult.Yes} Dim command2 As New DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutCommand() With {.Text = "Cancel", .Result = System.Windows.Forms.DialogResult.No} action.Commands.Add(command1) action.Commands.Add(command2) Dim properties As New FlyoutProperties() properties.ButtonSize = New Size(100, 40) properties.Style = FlyoutStyle.MessageBox If FlyoutDialog.Show(Me, action, properties, predicate) = System.Windows.Forms.DialogResult.Yes Then e.Cancel = False Else e.Cancel = True End If End Sub
點(diǎn)擊復(fù)制