windowsforms-114564-controls-and-libraries-forms-and-user-controls-xtrausercontrol.md
The XtraUserControl class replaces the standard System.Windows.Forms.UserControl component. It provides the capability to create a stand-alone module populated with controls and components which can be reused throughout your application.
//Create an XtraUserControl that represents a login form
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" };
lc.AddItem(String.Empty, teLogin).TextVisible = false;
lc.AddItem(String.Empty, tePassword).TextVisible = false;
lc.AddItem(String.Empty, ceKeep);
this.Controls.Add(lc);
this.Dock = DockStyle.Fill;
}
}
//Show an XtraUserControl-based login form inside a dialog
private void simpleButton1_Click(object sender, EventArgs e) {
LoginUserControl myControl = new LoginUserControl();
DevExpress.XtraEditors.XtraDialog.Show(myControl, "Sign in", MessageBoxButtons.OKCancel);
}
'create an XtraUserControl that represents a login form
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"}
lc.AddItem(String.Empty, teLogin).TextVisible = False
lc.AddItem(String.Empty, tePassword).TextVisible = False
lc.AddItem(String.Empty, ceKeep)
Me.Controls.Add(lc)
Me.Dock = DockStyle.Fill
End Sub
End Class
'show an XtraUserControl-based login form inside a dialog
Private Sub simpleButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim myControl As New LoginUserControl()
DevExpress.XtraEditors.XtraDialog.Show(myControl, "Sign in", MessageBoxButtons.OKCancel)
End Sub
To add XtraUserControls at design-time, right-click your project and select the “Add DevExpress Item” option. This invokes the Template Gallery that allows you to add blank XtraUserControls and DevExpress forms, as well as template-based forms.
When compared to a standard WinForms UserControl, the XtraUserControl provides the following advantages: