Back to Devexpress

XtraDialog

windowsforms-114567-controls-and-libraries-messages-notifications-and-dialogs-xtradialog.md

latest5.0 KB
Original Source

XtraDialog

  • May 13, 2023
  • 3 minutes to read

XtraDialog is a message box that replaces standard dialogs. Like standard dialogs, it allows you to display a control (for example, a UserControl) and a button set in its client area. However, unlike standard dialogs, it supports DevExpress skins to apply a consistent appearance. For example, the image below shows a standard dialog that does not match the application’s theme.

The second image displays the same application with XtraDialog.

To display a dialog, call the static XtraDialog.Show method. This method’s parameters allow you to specify which control is displayed in its client area, specify the dialog’s caption, and add predefined buttons:

The following code invokes an XtraDialog displaying a UserControl with custom controls (two TextEdit controls and one CheckEdit control), and the OK and Cancel buttons:

csharp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraLayout;
using DevExpress.XtraPrinting.Export;

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

        private void simpleButton1_Click(object sender, EventArgs e) {
            LoginUserControl myControl = new LoginUserControl();
            if(XtraDialog.Show(myControl, "Sign in", MessageBoxButtons.OKCancel) == DialogResult.OK) {
                /*
                * string login = myControl.Login;
                * string password = myControl.Password;
                */
            }
        }
    }

    public class LoginUserControl : XtraUserControl {
        TextEdit teLogin;
        TextEdit tePassword;
        public LoginUserControl() {
            LayoutControl lc = new LayoutControl();
            lc.Dock = DockStyle.Fill;
            this.teLogin = new TextEdit();
            this.tePassword = new TextEdit();
            tePassword.Properties.UseSystemPasswordChar = true;
            CheckEdit ceKeep = new CheckEdit() { Text = "Keep me signed in" };
            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;
        }
        public string Login {
            get { return teLogin.Text; }
        }
        public string Password {
            get { return tePassword.Text; }
        }
    }
}
vb
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraEditors
Imports DevExpress.XtraLayout
Imports DevExpress.XtraPrinting.Export

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 XtraDialog.Show(myControl, "Sign in", MessageBoxButtons.OKCancel) = System.Windows.Forms.DialogResult.OK Then    
                ' string login = myControl.Login;
                ' string password = myControl.Password;
            End If
        End Sub
    End Class

    Public Class LoginUserControl
        Inherits XtraUserControl

        Private teLogin As TextEdit
        Private tePassword As TextEdit
        Public Sub New()
            Dim lc As New LayoutControl()
            lc.Dock = DockStyle.Fill
            Me.teLogin = New TextEdit()
            Me.tePassword = New TextEdit()
            tePassword.Properties.UseSystemPasswordChar = True
            Dim ceKeep As New CheckEdit() With {.Text = "Keep me signed in"}
            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
        Public ReadOnly Property Login() As String
            Get
                Return teLogin.Text
            End Get
        End Property
        Public ReadOnly Property Password() As String
            Get
                Return tePassword.Text
            End Get
        End Property
    End Class
End Namespace