彩票走势图

logo DevExpress WinForm中文手册

弹出对话框


立即下载DevExpress WinForms

Flyout Dialog提供了类似于弹出内容容器的功能,允许您在应用程序UI管理器组件的WindowsUI视图中创建Windows 10风格的弹出消息,但是Flyout Dialog允许在应用程序中实现此功能,而无需使用任何其他组件。要显示弹出式消息框或弹出窗口,只需在代码中调用FlyoutDialog.Show方法。

C#:

DevExpress.XtraBars.Docking2010.Customization.FlyoutDialog.Show(. . .);

点击复制

VB.NET:

DevExpress.XtraBars.Docking2010.Customization.FlyoutDialog.Show(. . .)

点击复制

Show方法有多个重载。根据选择的重载,必须将所有者、控件、弹出动作、弹出属性和谓词作为参数传递。

  • Owner——将拥有显示的弹出式消息框或弹出框的表,使用此关键字可将当前表单设置为弹出框的父表单。
  • Control——在弹出框中显示的控件或UserControl对象,下图展示了一个空白的弹出式窗口,其中包含一个WindowsUIButtonPanel。
Winforms结果弹出框

FlyoutAction ——一个FlyoutAction对象,它包含标题、描述、图像和一组在这个弹出框中显示的按钮。下图展示了一个示例。

Winforms弹出对象

下面的代码创建了一个带有自定义标题、描述和两个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);

点击复制

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)

点击复制

提示:如果将 和FlyoutAction传递给FlyoutDialog.Show方法,FlyoutAction的标题和按钮将被显示,而描述和图像将被隐藏。

Flyout Properties——一个 DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutProperties对象,用于存储显示的弹出框的高级属性。例如,下面代码中的Style属性允许您选择弹出样式(在整个表单中显示的消息框或弹出窗口),ButtonSize属性设置自定义动作按钮的大小。

C#:

FlyoutProperties properties = new FlyoutProperties();
properties.ButtonSize = new Size(100, 40);
properties.Style = FlyoutStyle.MessageBox;

点击复制

VB.NET:

Dim properties As New FlyoutProperties()
properties.ButtonSize = New Size(100, 40)
properties.Style = FlyoutStyle.MessageBox

点击复制

Predicate——引用一个布尔函数的谓词,该函数接受一个DialogResult 值作为参数。该函数根据弹出框的输出DialogResult 指定是否可以关闭弹出框,谓词强制最终用户单击弹出按钮,从而确保弹出不会通过任何其他方式关闭(例如,按“Esc”按钮)。下面的代码演示了一个示例。

C#:

Predicate<DialogResult> predicate = canCloseFunc;

private static bool canCloseFunc(DialogResult parameter) {
return parameter != DialogResult.Cancel;
}

点击复制

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

点击复制

Show方法返回 DialogResult枚举器值,该值允许检查单击了哪个FlyoutCommand。使用这个和上面的信息,您可以在父表单关闭时显示一个弹出对话框,如下面的代码所示。这段代码显示了一个带有两个按钮的弹出消息框,使用的谓词确保flyout只有在终端用户在“Close”和“Cance”选项之间选择后才会关闭。

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

点击复制

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

点击复制

扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP