原創(chuàng)|使用教程|編輯:郝浩|2013-05-15 14:43:32.000|閱讀 1825 次
概述:FlowChart.NET現(xiàn)在更名為MindFusion.Diagramming for WinForms,這個(gè)是一個(gè)通用的軟件組件,提供了用于創(chuàng)建或編輯圖表的直觀的用戶交互模型。本文將會(huì)詳解如何自定義組件。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
自定義組件:
創(chuàng)建自定義組件,可以源自任何內(nèi)置的組件類,最終是從ComponentBase類。通常想要覆蓋Draw方法,是為了渲染組件和最終的GetDesiredSize方法。下面是一個(gè)簡(jiǎn)單的自定義組件的方法:
C#
public class RectangleComponent : ComponentBase { protected override void Draw(MindFusion.Drawing.IGraphics graphics, RenderOptions options) { graphics.DrawRectangle(Pens.Red, Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height); } }
上面出來(lái)的組件只會(huì)呈現(xiàn)紅色的矩形。在FlowChart.NET中也提供了基于用戶輸入的自定義組件行為,覆蓋了OnMouseDown、 OnMouseUp、 OnMouseMove、OnKeyDown、OnKeyUp、 OnKeyPress方法。
自定義面板:
為了創(chuàng)建一個(gè)自定義的容器組件,需要從ContainerComponent派生類并覆蓋ArrangeComponents方法和最終GetDesiredSize方法。從ArrangeComponents方法中,你可以安置單獨(dú)的子組件,通過(guò)它們的尺寸和面板的布局邏輯,分配給它們Bounds屬性值來(lái)實(shí)現(xiàn)。下面是一個(gè)簡(jiǎn)單的自定義面板的實(shí)例:
C#
public class OffsetPanel : ContainerComponent { public override void ArrangeComponents(RectangleF availableSpace, MindFusion.Drawing.IGraphics graphics) { float y = 0; foreach (ComponentBase component in Components) { // Calculate the desired size of the component SizeF desiredSize = component.GetDesiredSize(availableSpace.Size, graphics); component.Bounds = new RectangleF(y, y, desiredSize.Width, desiredSize.Height); component.ArrangeComponents(component.Bounds, graphics); y += 2; } } public override SizeF GetDesiredSize(SizeF availableSize, MindFusion.Drawing.IGraphics graphics) { float width = 0; float height = 0; float y = 0; for (int i = 0; i < Components.Count; i++) { ComponentBase component = Components[i]; SizeF desiredSize = component.GetDesiredSize(availableSize, graphics); width = Math.Max(width, desiredSize.Width + y); height = Math.Max(height, desiredSize.Height + y); y += 2; }
return new SizeF(width, height); } }
在XML中使用自定義組件
如果想要在XML中使用自定義組件,你需要提供了一個(gè)自定義ITypeResolver對(duì)象給loader。如果你想要你的組件使用快捷方式的名稱,這個(gè)比較好用。如果說(shuō)你沒(méi)有提供一個(gè)ITypeResolver,加載這個(gè)XML就會(huì)失敗。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件