原創|使用教程|編輯:郝浩|2013-05-15 14:43:32.000|閱讀 1825 次
概述:FlowChart.NET現在更名為MindFusion.Diagramming for WinForms,這個是一個通用的軟件組件,提供了用于創建或編輯圖表的直觀的用戶交互模型。本文將會詳解如何自定義組件。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
自定義組件:
創建自定義組件,可以源自任何內置的組件類,最終是從ComponentBase類。通常想要覆蓋Draw方法,是為了渲染組件和最終的GetDesiredSize方法。下面是一個簡單的自定義組件的方法:
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); } }
上面出來的組件只會呈現紅色的矩形。在FlowChart.NET中也提供了基于用戶輸入的自定義組件行為,覆蓋了OnMouseDown、 OnMouseUp、 OnMouseMove、OnKeyDown、OnKeyUp、 OnKeyPress方法。
自定義面板:
為了創建一個自定義的容器組件,需要從ContainerComponent派生類并覆蓋ArrangeComponents方法和最終GetDesiredSize方法。從ArrangeComponents方法中,你可以安置單獨的子組件,通過它們的尺寸和面板的布局邏輯,分配給它們Bounds屬性值來實現。下面是一個簡單的自定義面板的實例:
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中使用自定義組件,你需要提供了一個自定義ITypeResolver對象給loader。如果你想要你的組件使用快捷方式的名稱,這個比較好用。如果說你沒有提供一個ITypeResolver,加載這個XML就會失敗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件