AABBbaby

导航

DevExpress WinForms中文帮助文档:表单控件 - XtraUserControl

点击获取DevExpress完整版下载

DevExpress WinForms拥有180+组件和UI库,能为Windows Forms平台创建具有影响力的业务解决方案。DevExpress WinForms能完美构建流畅、美观且易于使用的应用程序,无论是Office风格的界面,还是分析处理大批量的业务数据,它都能轻松胜任!

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皮肤,并确保整个应用程序的外观一致性。

上DevExpress中文网,获取第一手最新产品资讯!

DevExpress技术交流群3:700924826      欢迎一起进群讨论

posted on 2021-01-29 10:01  AABBbaby  阅读(414)  评论(0编辑  收藏  举报