2012-02-18 24 views
2

我在SplitContainer的左側有一個TreeView,我希望右側的內容在點擊TreeNode時發生變化。我想要做的是設置「窗口」,例如Putty中的設置,即右側的內容可能非常複雜。c#使用SplitContainer中的TreeView控件來更改內容

Putty http://unixwiz.net/images/putty-openssh-3.gif

的想法我已經是有針對每個樹節點內容的面板,所有這些面板添加到右側,顯示/隱藏他們基於在樹視圖點擊。

這是正確的做法嗎?有更好的嗎?鏈接樹節點與其面板的最佳方式是什麼,例如某種MVC?

謝謝

湯姆

+0

迄今爲止的WinForms實現這個最簡單的方法是用一個TabControl,減去標籤:http://stackoverflow.com/questions/2340566/creating-wizards-for -windows-forms-in-c-sharp/2342320#2342320 – 2012-02-18 14:30:28

+0

我的博文,[實現分頁選項對話框](http://www.differentpla.net/content/2004/10/implementing-a-paged-options -dialog),可能會給你一些提示。源代碼是[在github上](https://github.com/rlipscombe/paged-options-dialog)。 – 2012-02-18 14:09:38

回答

2

你可以有單獨的設計師接受上下文對象來填充或保存相關設置 然後在你的TreeView控件,您可以使用每個節點的標籤屬性,以多個面板維護相關面板,選擇它時在右側面板中顯示面板。

下面是一些代碼:

interface ISettingPanel 
{ 
SettingContext Context{get;set;} 
} 

public BasicSettingPanel:Panel,ISettingPanel 
{ 
.... 
} 

public void InitTreeView 
{ 
var node=new TreeNode(); 
node.Tage=new BasicSettingPanel();// or you can set the type to create the panel later 
treeView.Nodes.Add(node); 
} 

public void AfterNodeSelected() 
{ 
_currentPanel=null; 
var selectedNode=treeView.SelectedNode; 
var panel=selectedNode.Tag as Panel; 
if(panel!=null) 
_currentPanel=panel; 
(_currentPanel as ISettingPanel).Context=this.Context; 
} 
+0

甜美,謝謝 – scibuff 2012-02-18 16:13:28

+0

不客氣:) – Beatles1692 2012-02-18 23:40:00