原創|使用教程|編輯:郝浩|2013-06-09 14:11:34.000|閱讀 421 次
概述:FlowChart.NET是一個通用的流程圖控件,提供了用于創建或編輯圖表的直觀的用戶交互模型。在本文中將會繼續創建一個自定義的CompositeNode 類,用于顯示在組織中的獨立信息,如名稱、 說明和圖像。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
FlowChart.NET是一個通用的流程圖控件,提供了用于創建或編輯圖表的直觀的用戶交互模型。在前面的教程中,已經說明了一部分如何自定義節點,在本文中將會繼續創建一個自定義的CompositeNode 類,用于顯示在組織中的獨立信息,如名稱、 說明和圖像。節點將會通過各種公開的屬性進行自定義。
4、定義節點屬性
要能夠自定義節點,我們需要公開幾個屬性。在這種情況下,屬性只是作為基礎組件屬性的包裝。在構造函數之后添加以下代碼:
C#
public MindFusion.Drawing.Pen Stroke { get { return shape.Pen; } set { shape.Pen = value; } } public MindFusion.Drawing.Brush Fill { get { return shape.Brush; } set { shape.Brush = value; } } public Image Image { get { return image.Image; } set { image.Image = value; } } public string Title { get { return title.Text; } set { title.Text = value; } } public string FullName { get { return fullName.Text; } set { fullName.Text = value; } } public string Text { get { return text.Text; } set { text.Text = value; } }
Visual Basic
Public Property Stroke() As MindFusion.Drawing.Pen Get Return _shape.Pen End Get Set(ByVal value As MindFusion.Drawing.Pen) _shape.Pen = value End Set End Property Public Property Fill() As MindFusion.Drawing.Brush Get Return _shape.Brush End Get Set(ByVal value As MindFusion.Drawing.Brush) _shape.Brush = value End Set End Property Public Property Image() As Image Get Return _image.Image End Get Set(ByVal value As Image) _image.Image = value End Set End Property Public Property Title() As String Get Return _title.Text End Get Set(ByVal value As String) _title.Text = value End Set End Property Public Property FullName() As String Get Return _fullName.Text End Get Set(ByVal value As String) _fullName.Text = value End Set End Property Public Property Text() As String Get Return _text.Text End Get Set(ByVal value As String) _text.Text = value End Set End Property
5、指定默認值
在組件內容已經加載以及引用到感興趣的組件已經獲得后,默認值可以提供在構造函數中。下面的代碼將會設置白色的背景和黑色的邊界作為新節點的默認值:
C#
Stroke = new MindFusion.Drawing.Pen(Color.Black, 0);
Fill = new MindFusion.Drawing.SolidBrush(Color.White);
Visual Basic
Stroke = New MindFusion.Drawing.Pen(Color.Black, 0)
Fill = New MindFusion.Drawing.SolidBrush(Color.White)
6、使用自定義節點類
假設我們有一個現成的WinForms應用程序,并且包含一個名為diagram1圖變量,兩個圖像已經被添加到這個應用程序作為資源,分別命名為Image1和Image2。下面的代碼創建了兩個OrgChartNode類的新實例,并使用一個鏈接將這兩進行連接:
C#
OrgChartNode node1 = new OrgChartNode(diagram1); node1.Bounds = new RectangleF(20, 10, 80, 40); node1.Title = "CEO"; node1.FullName = "John Smith"; node1.Text = "Our beloved leader. \r\n" + "The CEO of this great corporation."; node1.Image = Properties.Resources.Image1; diagram1.Nodes.Add(node1); OrgChartNode node2 = new OrgChartNode(diagram1); node2.Bounds = new RectangleF(60, 60, 80, 40); node2.Title = "CIO"; node2.FullName = "Bob Smith"; node2.Text = "The CIO of this great corporation."; node2.Image = Properties.Resources.Image2; diagram1.Nodes.Add(node2); diagram1.Factory.CreateDiagramLink(node1, node2);
Visual Basic
Dim node1 As New OrgChartNode(diagram1) node1.Bounds = New RectangleF(20, 10, 80, 40) node1.Title = "CEO" node1.FullName = "John Smith" node1.Text = "Our beloved leader. \r\n" & _ "The CEO of this great corporation." node1.Image = My.Resources.Image1 diagram1.Nodes.Add(node1) Dim node2 = New OrgChartNode(diagram1) node2.Bounds = New RectangleF(60, 60, 80, 40) node2.Title = "CIO" node2.FullName = "Bob Smith" node2.Text = "The CIO of this great corporation." node2.Image = My.Resources.Image2 diagram1.Nodes.Add(node2) diagram1.Factory.CreateDiagramLink(node1, node2)
運行應用程序將會給出類似于下面的圖片的結果:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件