构建向导的好模式?

发布于 2024-08-25 15:36:54 字数 76 浏览 11 评论 0原文

我通常使用 TabControl 并以某种方式隐藏选项卡并浏览它们。

我很好奇这样做的其他方法!

I usually use a TabControl and somehow hide the tabs and navigate through them.

I am curious about other ways of doing this!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素手挽清风 2024-09-01 15:36:54

您可以使用面板对象,除了第一个面板外,所有面板的 Visible 属性都设置为 false

存储当前面板的索引,并具有可适当更改此索引的“下一个”和“上一个”按钮。更改此索引后,根据需要使相应的面板可见/不可见(在给定时间仅当前面板应可见)。

您还可以处理部分/所有面板上的 IsVisibleChanged 事件,以在用户导航到特定面板时触发某些行为。

You could use a collection of Panel objects, with all but the first panel having their Visible property set to false.

Store the index of the current panel, and have "Next" and "Previous" buttons that change this index appropriately. When this index is changed, make the appropriate panels visible/not visible as needed (only the current panel should be visible at a given time).

You can also handle the IsVisibleChanged event on some/all of your panels, to trigger certain behaviors to occur when the user navigates to a particular panel.

一个人的夜不怕黑 2024-09-01 15:36:54

这是一个相当复杂的话题;大约两年前,我构建了一个相当全面的向导控件供内部使用,我记得花了几周的时间才完全正常工作。

基本元素包括:

  • 标题面板
  • 内容面板
  • 操作面板
  • 侧边栏

内容面板和操作面板都使用 ParentControlDesigner 来启用放置控件。内容面板不允许您直接将其拖放到其上,而是允许您将其拖放到活动页面(子面板)上。操作面板还有一个“默认”模式,它创建标准的 4 个按钮(上一个、下一个、取消、完成)。我主要实现了自定义模式,以便可以对其进行换肤,即使用 DevEx 按钮而不是标准 Winforms 按钮。

标头基本上是静态的,它是一个 PictureBoxLabel,可自定义图像、文本和字体。 (默认情况下,文本与页面标题相同,字体是添加粗体样式的控件字体)。

然后是 API 公开的一组数据结构:

  • 步骤(包含名称、标题等,还指定它们是否应在侧边栏中链接)
  • 工作流程(即根据您的选择进入下一步)
  • 验证事件(同步和异步)
  • 操作(在页面更改、按钮单击等之前/之后运行)
  • 过渡效果(我这样做是为了好玩,用户喜欢他们)

我为这些步骤组合了一个自定义集合编辑器,如上所述,这又为内容面板创建子面板。每个面板都直接添加到控件集合中,但根据活动步骤属性一次只能看到一个面板。我记得对接似乎从来都不太正常,所以我必须覆盖所有调整大小的方法。我从来没有花时间创建一个智能标签来轻松地在页面之间翻转,但可以在属性网格上选择活动页面(或页面索引)。

然后我还必须包含一大堆钩子,用于在各个页面上插入任何自定义逻辑。如果不发布所有代码,很难真正深入了解这里的细节。

正确的设计和测试是相当耗时的,但我不记得使用过任何高超的设计技巧,只是必须有条不紊地解决问题,如上所述,从各个 UI 元素(运行时和设计时)的角度来看和数据结构以及它们如何交互。

请记住,所有这些都是为了创建可重用的向导组件,因为我们需要为特定应用程序开发大约 10 个向导组件(并且它对于其他项目也很方便)。如果我只需要编写一个快速向导,我可能不会经历所有这些麻烦,我只会做你正在做的事情 - 使用选项卡控件和一些流程面板。或者更好的是,我会使用现成的向导控件,现在许多 Winforms 库(例如 DX 库)中都提供了该控件。

This is a pretty involved topic; I built a fairly comprehensive Wizard control about two years ago for use in house and I remember it taking several weeks to get working exactly right.

The basic elements are:

  • Header panel
  • Content panel
  • Action panel
  • Sidebar

Both the content panel and action panel make use of the ParentControlDesigner to enable dropping controls. The content panel doesn't let you drop directly on it, instead it lets you drop on the active page (sub-panel). The action panel also has a "default" mode where it creates the standard 4 buttons (prev, next, cancel, finish). I mainly implemented the custom mode so I could skin it, i.e. using the DevEx buttons instead of the standard Winforms buttons.

The header is basically static, it's a PictureBox and Label with the image, text, and font customizable. (By default the text is the same as the page title and the font is the control's font with bold style added).

Then there are a set of data structures exposed by the API:

  • Steps (with name, title, etc., also specify whether or not they should be linked in sidebar)
  • Workflows (i.e. where you're taken to next based on your choices)
  • Validation events (both synchronous and asynchronous)
  • Actions (to be run before/after page change, button clicks, etc.)
  • Transition effects (I did these for fun, users like 'em)

I put together a custom collection editor for the steps, which in turn create sub-panels for the content panel as explained above. Each panel is just added straight to the control collection, but only one is ever visible at a time based on the active step property. I remember that docking never seemed to work quite right so I had to override all of the resize methods. I never did get around to creating a smart tag to easily flip between pages, but the active page (or page index) can be chosen on the property grid.

Then I also had to include a whole bunch of hooks for inserting any custom logic on individual pages. Hard to really get into much detail here without posting all the code.

It's pretty time-consuming to properly design and test, but I don't remember using any whizbang design tricks, just had to approach the problem methodically, as mentioned, from the perspective of the individual UI elements (both runtime and design-time) and data structures and how they interact.

Keep in mind all of this was for the purpose of creating a reusable Wizard component because we needed to develop about 10 of them for a particular app (and it's come in handy for other projects as well). If I just needed to hack together one quick wizard, I probably wouldn't go through all this trouble, I'd just do what you're doing - use a tab control and a few flow panels. Or better yet I'd use an off-the-shelf wizard control as are available in many Winforms libraries now, like the DX library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文