XtraUserControl
- 2 minutes to read
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);
}
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:
- End-users can scroll the XtraUserControl content when hovering it, without needing to focus it first;
- Communicates with the Layout and Data Layout Controls component to pass the correct control sizes;
- Allows you to utilize smart tags and Designer dialogs for controls inside an XtraUserControl (or its descendant) directly from a form that hosts this container (visual inheritance);
- Supports DevExpress skins and ensures look-and-feel consistency across the application.