logo Devexpress Winforms中文手册 我也要发布文档

XtraDialog


点击获取DevExpress完整版下载

XtraDialog是一个消息框,它代替了标准对话框。 与标准对话框一样,它允许您在其工作区中显示控件(例如,UserControl)和按钮集。 但与标准对话框不同,它支持DevExpress皮肤来提供一致的外观。例如,下图显示了与应用程序主题不匹配的标准对话框。

DevExpress WinForms帮助文档

第二个图像使用XtraDialog显示相同的应用程序。

DevExpress WinForms帮助文档

要显示对话框,请调用静态XtraDialog.Show方法。 方法参数允许您指定哪个控件显示在其工作区中,提供对话框的标题并添加预定义的按钮:

下面的代码调用一个XtraDialog,它显示带有自定义控件(两个TextEdit控件和一个CheckEdit控件)以及OK和Cancel按钮的UserControl:

DevExpress WinForms帮助文档

C#

using DevExpress.XtraEditors;
using DevExpress.XtraLayout;
using System;
using System.Windows.Forms;

namespace WindowsFormsApp1 {
public partial class Form3 : Form {
public Form3() {
InitializeComponent();
}

private void simpleButton1_Click(object sender, EventArgs e) {
LoginUserControl myControl = new LoginUserControl();
if (DevExpress.XtraEditors.XtraDialog.Show(myControl, "Sign in", MessageBoxButtons.OKCancel) == DialogResult.OK) {
// do something
}
}
}

public class LoginUserControl : XtraUserControl {
public LoginUserControl() {
LayoutControl lc = new LayoutControl();
lc.Dock = DockStyle.Fill;
TextEdit teLogin = new TextEdit();
TextEdit tePassword = new TextEdit();
CheckEdit ceKeep = new CheckEdit() { Text = "Keep me signed in" };
SeparatorControl separatorControl = new SeparatorControl();
lc.AddItem(String.Empty, teLogin).TextVisible = false;
lc.AddItem(String.Empty, tePassword).TextVisible = false;
lc.AddItem(String.Empty, ceKeep);
this.Controls.Add(lc);
this.Height = 100;
this.Dock = DockStyle.Top;

}
}
}

VB.NET

Imports DevExpress.XtraEditors
Imports DevExpress.XtraLayout
Imports System
Imports System.Windows.Forms

Namespace WindowsFormsApp1
Partial Public Class Form3
Inherits Form

Public Sub New()
InitializeComponent()
End Sub

Private Sub simpleButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim myControl As New LoginUserControl()
If DevExpress.XtraEditors.XtraDialog.Show(myControl, "Sign in", MessageBoxButtons.OKCancel) = DialogResult.OK Then
' do something
End If
End Sub
End Class

Public Class LoginUserControl
Inherits XtraUserControl

Public Sub New()
Dim lc As New LayoutControl()
lc.Dock = DockStyle.Fill
Dim teLogin As New TextEdit()
Dim tePassword As New TextEdit()
Dim ceKeep As New CheckEdit() With {.Text = "Keep me signed in"}
Dim separatorControl As New SeparatorControl()
lc.AddItem(String.Empty, teLogin).TextVisible = False
lc.AddItem(String.Empty, tePassword).TextVisible = False
lc.AddItem(String.Empty, ceKeep)
Me.Controls.Add(lc)
Me.Height = 100
Me.Dock = DockStyle.Top
End Sub
End Class
End Namespace