轉(zhuǎn)帖|使用教程|編輯:龔雪|2020-09-25 09:35:54.797|閱讀 707 次
概述:DevExpress Winforms Controls 內(nèi)置140多個UI控件和庫,完美構(gòu)建流暢、美觀且易于使用的應(yīng)用程序。在本文中,我們將為大家介紹DevExpress WidgetView的使用,歡迎下載最新版控件體驗!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
DevExpress Winforms Controls 內(nèi)置140多個UI控件和庫,完美構(gòu)建流暢、美觀且易于使用的應(yīng)用程序。DevExpress WinForm v20.1全新發(fā)布,想要體驗?點擊下載>>
很多程序可能都會有一個半島外圍網(wǎng)上直營綜合展示系統(tǒng)的相關(guān)信息,如匯總信息,圖表統(tǒng)計、待辦業(yè)務(wù)、提醒信息等內(nèi)容,在Web上可能叫做Dashboard儀表板,或者半島外圍網(wǎng)上直營頁面,不管哪種叫法,都是綜合展示一些信息,提供一些信息展示或者處理工作的入口,我們在Winform里面,有時候也需要這樣的儀表板半島外圍網(wǎng)上直營,這個使用DevExpress的控件組的話,可以使用WidgetView控件來實現(xiàn)。
DevExpress的Demo樣例提供了一些WidgetView的樣式,如下所示。
 
 
 
通過上面的案例,我們可以看到,利用WidgetView可以創(chuàng)建很豐富的匯總、報表、待辦等相關(guān)內(nèi)容,只要處理得當(dāng),可以為我們的Dashboard半島外圍網(wǎng)上直營提供很豐富的綜合內(nèi)容展示。
WidgetView的使用,如果要較好掌握它的使用,需要了解DocumentManager、WidgetView、Document、StackGroup的概念是什么,以及它們之間的關(guān)系。
我們可以通過窗體的設(shè)計器來創(chuàng)建一個DocumentManager,其中DocumentManager里面包含一個WidgetView,用來做視圖管理的;然后在設(shè)計模式上創(chuàng)建多個對應(yīng)的Document,而Document是用來管理對應(yīng)展示的內(nèi)容的(如自定義用戶控件),StackGroup等是用來管理Document布局展示的,除了StackLayout外,可以通過WidgetView的LayoutMode屬性設(shè)置其他布局類型,如Table Layout, Flow Layout 以及 Free Layout等。如下是在設(shè)計模式下創(chuàng)建幾個空白的Document以及使用的LayoutMode 為StackLayout來排版Document的排列方式。
 
如果需要在設(shè)計模式下維護(hù)WidgetView的一些內(nèi)容,可以通過窗體下面的DocumentManager對象進(jìn)行維護(hù)。
 
以上的Demo就是簡單的創(chuàng)建幾個空白的Document以及常規(guī)的StackLayout的方式排版,運(yùn)行得到界面效果如下所示。
 
一般實際情況下,我們是在半島外圍網(wǎng)上直營上綜合展示各種報表內(nèi)容、圖表內(nèi)容、待辦信息等內(nèi)容的,那么各個模塊的內(nèi)容,可以使用自定義用戶控件來處理,然后綜合展示即可,實際情況下,首先我們先創(chuàng)建用戶控件界面,以及實現(xiàn)好各個內(nèi)容的展示;然后我們可以在設(shè)計模式下指定不同Document下容納的控件信息,也可通過動態(tài)創(chuàng)建的方式創(chuàng)建所需要的內(nèi)容。
以下是我使用代碼動態(tài)構(gòu)建的WidgetView界面,通過動態(tài)創(chuàng)建DocumentManager、Document,以及加載各種自定義用戶控件,組合成下面的界面效果。
 
用戶自定義控件界面,我們在Controls里面放置各種不同內(nèi)容的用戶控件,如下界面方案中的項目文件界面所示。
 
動態(tài)創(chuàng)建WidgetView相關(guān)的內(nèi)容比較簡單,我這里把所有相關(guān)的代碼一并貼出,方便了解。
/// <summary>
/// 動態(tài)構(gòu)建的Widget View
/// </summary>
public partial class FrmWidget2 : DevExpress.XtraEditors.XtraForm
{
public FrmWidget2()
{
InitializeComponent();
}
private void FrmWidget2_Load(object sender, EventArgs e)
{
AddDocumentManager();
}
WidgetView view;
StackGroup group1, group2;
void AddDocumentManager()
{
var docMananger = new DocumentManager(components);
view = new WidgetView();
docMananger.View = view;
docMananger.ContainerControl = this;
view.AllowDocumentStateChangeAnimation = DevExpress.Utils.DefaultBoolean.True;
group1 = new StackGroup();
group2 = new StackGroup();
group1.Length.UnitType = LengthUnitType.Star;
group1.Length.UnitValue = 2;
view.StackGroups.AddRange(new StackGroup[] { group1, group2 });
//添加文檔
AddDocuments();
//設(shè)置布局顯示
view.LayoutMode = LayoutMode.StackLayout;
view.DocumentSpacing = 3;
//tableLayout的行列定義
//構(gòu)建每個文檔所屬的ColumnIndex和RowIndex
this.view.Rows.Clear();
this.view.Columns.Clear();
List<Point> points = new List<Point>();
for (int i = 0; i < 3; i++)
{
this.view.Rows.Add(new RowDefinition() { });
for (int j = 0; j < 2; j++)
{
this.view.Columns.Add( new ColumnDefinition());
points.Add(new Point(i, j));
}
}
Random random = new Random();
foreach (Document document in view.Documents)
{
Point newLocation = points[random.Next(points.Count)];
document.RowIndex = newLocation.Y;
document.ColumnIndex = newLocation.X;
points.Remove(newLocation);
}
//添加 Document對象到group1不是必須的,因為所有新創(chuàng)建的文檔都是默認(rèn)放置到第一個StackGroup中.
//group1.Items.AddRange(new Document[] { view.Documents[0] as Document, view.Documents[1] as Document });
view.Controller.Dock(view.Documents[view.Documents.Count - 3] as Document, group2);
view.Controller.Dock(view.Documents[view.Documents.Count - 2] as Document, group2);
view.Controller.Dock(view.Documents[view.Documents.Count - 1] as Document, group2);
}
/// <summary>
/// 動態(tài)添加用戶控件作為Widget視圖的文檔內(nèi)容
/// </summary>
void AddDocuments()
{
CreateDocument(typeof(Calendar), "日歷控件", Color.Blue);
CreateDocument(typeof(ToDoList), "待辦列表4", Color.Yellow);
CreateDocument(typeof(News), "消息信息", Color.Navy);
CreateDocument(typeof(TodoControl), "待辦控件", Color.Red);
CreateDocument(typeof(MyDateControl), "日期控件", Color.Green);
CreateDocument(typeof(Mail), "郵箱信息", Color.Purple);
}
/// <summary>
/// 創(chuàng)建指定的文檔
/// </summary>
/// <param name="controlType">文檔用戶控件對象類型</param>
/// <param name="caption">標(biāo)題</param>
/// <param name="backColor">背景色</param>
void CreateDocument(Type controlType, string caption, Color backColor)
{
//創(chuàng)建用戶控件
var control = Activator.CreateInstance(controlType) as Control;
//創(chuàng)建指定的文檔
var document = view.AddDocument(control) as Document;
document.Caption = caption;
//背景色
document.AppearanceCaption.BackColor = backColor;
}
}
以上就是DevExpress的WidgetView的各種相關(guān)內(nèi)容的介紹,以及介紹在設(shè)計模式下、代碼動態(tài)構(gòu)建兩種方式下的處理方式,希望對你了解這個特殊的控件有所幫助。
本文轉(zhuǎn)載自
DevExpress技術(shù)交流群2:775869749 歡迎一起進(jìn)群討論
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉(zhuǎn)載自: