DevExpress WinForms Subscription拥有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技术交流群3:700924826 欢迎一起进群讨论
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/2221.html