你可以有單獨的設計師接受上下文對象來填充或保存相關設置 然後在你的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;
}
迄今爲止的WinForms實現這個最簡單的方法是用一個TabControl,減去標籤:http://stackoverflow.com/questions/2340566/creating-wizards-for -windows-forms-in-c-sharp/2342320#2342320 – 2012-02-18 14:30:28
我的博文,[實現分頁選項對話框](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