我会使用 TabControl 来“模拟”一个向导(请注意,我个人没有在 Windows Mobile/Compact FrameWork 上下文中使用 TabControl,但它已被 Microsoft 正式列为“Windows CE、Windows Mobile for掌上电脑。”请参阅:TabControl
如果您想创建类似向导的用户体验,在 WinForms 中有一个隐藏选项卡的简单技巧:在 Form 'Load 事件中,将 Tabcontrol 的 Region 设置为 TabControl 的 DisplayRectangle。
tabControl1.Region = new Region(tabControl1.DisplayRectangle);
如果这对您有用,它将为您节省大量移动“用户控件”或“面板”的麻烦,并且您可以在设计时以可视模式设计您的 TabPage,然后以您认为最好的任何方式控制从 TabPage 到 TabPage 的导航.
如果您想将选项卡恢复到视图中,您可能希望在 Form 'Load 事件中“快照”TabControl 的原始区域。
这是一个简单的例子:一种“单向”从头到尾的模型:
定义一个字典,其中每个 Key 是一个 TabPage,每个 Key 条目的布尔值控制您是否允许用户导航到该 TabPage。
// allocate the Dictionary
Dictionary<TabPage, bool> CanNavigateDict = new Dictionary<TabPage, bool>();
您将希望“通过在表单加载事件中执行以下操作来准备该字典:
foreach (TabPage theTPage in tabControl1.TabPages)
{
CanNavigateDict.Add(theTPage, false);
}
// show the first TabPage
tabControl1.SelectedTab = tabPage1;
此模型中的导航控件意味着您需要将下一个 TabPage 的布尔值设置为 'true,当您通过任何方式满足完成当前页面的条件时:示例
// sample of how you control navigation in the TabControl
// by using the CanNavigate Dictionary in the TabControl 'Selecting event
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
e.Cancel = ! CanNavigateDict[e.TabPage];
}