文檔首頁>>DevExpress WinForm中文手冊>>XtraUser控件
XtraUser控件
XtraUserControl 類替代標(biāo)準(zhǔn)的System.Windows.Forms.UserControl 組件,它提供了創(chuàng)建包含控件和組件的獨(dú)立模塊的功能,這些模塊可以在整個(gè)應(yīng)用程序中重復(fù)使用。
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
要在設(shè)計(jì)時(shí)添加XtraUserControls,請右鍵單擊您的項(xiàng)目,然后選擇 "Add DevExpress Item" 選項(xiàng),這將調(diào)用DevExpress Template Gallery
,該庫允許您添加空白XtraUserControls和DevExpress表單以及基于模板的表單。
與標(biāo)準(zhǔn)WinForms UserControl相比,XtraUserControl具有以下優(yōu)點(diǎn):
- 最終用戶可以在懸停時(shí)滾動(dòng)XtraUserControl內(nèi)容,而無需首先關(guān)注它。
- 與布局和數(shù)據(jù)布局控件組件通信來傳遞正確的控件大小。
- 允許您直接從承載此容器的表單(可視繼承)中為XtraUserControl(或其子)內(nèi)部的控件使用智能標(biāo)記和Designer對話框。
- 支持DevExpress皮膚,并確保整個(gè)應(yīng)用程序的外觀一致性。