在 C# 中为 Windows 窗体创建向导 [英] Creating Wizards for Windows Forms in C#

查看:31
本文介绍了在 C# 中为 Windows 窗体创建向导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是在 C# .Net 中为 Windows 窗体应用程序创建向导的新手.所以我对向导创建没有任何想法.请给我一些关于创建多向导的想法.

I am new in Creating Wizards for Windows Forms Application in C# .Net. So i don't have any idea in wizard creation. Please give me some ideas about creating Multiple wizard.

问候,拉维

推荐答案

有很多方法可以做到.为每个向导步骤创建一个表单是可能的,但非常笨拙.当用户更改步骤时,丑陋,大量闪烁.使每个步骤都成为 UserControl 可以工作,您只需将它们切换进和切换出表单的 Controls 集合.或者为每一步设置一个 Visible = true.UC 设计往往会变得复杂,您必须为每个 UI 项添加公共属性.

Lots of ways to do it. Creating a form for each wizard step is possible, but very awkward. And ugly, lots of flickering when the user changes the step. Making each step a UserControl can work, you simply switch them in and out of the form's Controls collection. Or make one of them Visible = true for each step. The UC design tends to get convoluted though, you have to add public properties for each UI item.

简单且 RAD 的方法是使用 TabControl.在设计器中运行良好,因为它允许您在设计时切换选项卡并在每个选项卡上放置控件.切换步骤很简单,只需更改 SelectedIndex 属性即可.唯一重要的是在运行时隐藏选项卡.通过处理 Windows 消息仍然很容易做到.向您的表单添加一个新类并粘贴如下所示的代码.编译.将新控件从工具箱顶部拖放到表单上.

The easy and RAD way is to use a TabControl. Works very well in the designer since it allows you to switch tabs at design time and drop controls on each tab. Switching steps is trivial, just change the SelectedIndex property. The only thing non-trivial is to hide the tabs at runtime. Still easy to do by processing a Windows message. Add a new class to your form and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form.

using System;
using System.Windows.Forms;

class WizardPages : TabControl {
  protected override void WndProc(ref Message m) {
    // Hide tabs by trapping the TCM_ADJUSTRECT message
    if (m.Msg == 0x1328 && !DesignMode) m.Result = (IntPtr)1;
    else base.WndProc(ref m);
  }
}

这篇关于在 C# 中为 Windows 窗体创建向导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆