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

XtraUserControl


点击获取DevExpress完整版下载

XtraUserControl 类替代标准的System.Windows.Forms.UserControl 组件,它提供了创建包含控件和组件的独立模块的功能,这些模块可以在整个应用程序中重复使用。

C#

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

VB.NET

'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

要在设计时添加XtraUserControls,请右键单击您的项目,然后选择 "Add DevExpress Item" 选项,这将调用Template Gallery,该库允许您添加空白XtraUserControls和DevExpress表单以及基于模板的表单。

与标准WinForms UserControl相比,XtraUserControl具有以下优点:

  • 最终用户可以在悬停时滚动XtraUserControl内容,而无需首先关注它;
  • 与布局和数据布局控件组件通信来传递正确的控件大小;
  • 允许您直接从承载此容器的表单(可视继承)中为XtraUserControl(或其子)内部的控件使用智能标记和Designer对话框;
  • 支持DevExpress皮肤,并确保整个应用程序的外观一致性。