在 Winforms 中控制用户工作流程

发布于 2024-08-17 19:44:21 字数 316 浏览 2 评论 0原文

我正在用 C# 构建一个 Winforms 应用程序,并且添加了一个具有三个选项卡的选项卡控件。

我想限制用户访问第二个选项卡页的能力,直到用户填写第一个选项卡。

我在第一个选项卡上有一个提交按钮,我希望当用户单击“提交”按钮时能够访问第二个选项卡。

我怎样才能做到这一点?

图片不可用

I'm building a Winforms application in C# and I have added a tab control that has three tabs.

I want to restrict user's ability to access the second tab page until user fills out the first tab.

I have a submit button the first tab, I want the second tab to be able to be accessed when the user clicks on the submit button.

How can I accomplish this?

Image unavailable

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

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

发布评论

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

评论(4

那请放手 2024-08-24 19:44:21

阻止用户选择选项卡会导致用户界面非常不直观。考虑创建一个“向导”,这是一个 UI 小工具,可以通过“下一步”按钮将用户从一个页面带到下一个页面。还有一个“后退”按钮,可选。您可以通过设置“下一步”按钮的“启用”属性来明确表明步骤已完成。

创建这样的向导可以使用 TabControl 来完成。将新类添加到您的项目中并粘贴下面所示的代码。编译。将新控件从工具箱顶部拖放到窗体上。在设计时,它看起来像一个普通的 TC,允许您添加每个向导步骤所需的控件。在运行时,选项卡是隐藏的。实现“下一步”和“后退”按钮很简单,只需更改 SelectedIndex 属性即可。

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);
  }
}

Preventing a user from selecting a tab makes for a very unintuitive user interface. Consider creating a "wizard", a UI gadget that takes the user from one page to the next with a Next button. And a Back button, optional. You can make it clear that a step is completed by setting the Next button's Enabled property.

Creating such a wizard can be done with a TabControl. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form. At design time it looks like a normal TC, allowing you to add the controls needed for each wizard step. At runtime the tabs are hidden. Implementing the Next and Back buttons is simple, just change the SelectedIndex property.

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);
  }
}
笨死的猪 2024-08-24 19:44:21

您可以禁用该选项卡,直到用户完成第一页:每次用户更改选项卡第一上的值时,验证选项卡的值并根据需要启用/禁用选项卡二。

但是,听起来您的流程不适合选项卡,也许更多类似“向导”的方法更合适,其中每个步骤都必须完成才能继续下一步?更多信息确实会有用。

编辑:如果您愿意,可以使用选项卡控件的 选择事件以取消选项卡更改。

You could just disable the tab until the user has completed page one: each time your user changes a value on tab one, validate the tab's values and enable/disable tab two as appropriate.

However, it doesn't sound like your process is suited to tabs, perhaps more of a 'Wizard' like approach would be appropriate, where each step must be completed before moving on to the next? More information would indeed be useful.

Edit: If you prefer you can use the Tab control's Selecting event to cancel a tab change.

好菇凉咱不稀罕他 2024-08-24 19:44:21

最简单的方法是使受限制的选项卡不可见或不启用。

The simplest ways would be to make the restricted tabs either not Visible or not Enabled.

咿呀咿呀哟 2024-08-24 19:44:21

已经说过多次了,但是您可以将选项卡 2 和 3 禁用或不可见,直到用户单击选项卡 1 中的提交按钮,验证字段,然后启用选项卡 2。如果 tab2 中有提交按钮,也可以对 tab3 执行相同的操作。

再次需要重申的是,从可用性的角度来看,这不是选项卡的最佳使用方式。如果您告诉我们应用程序正在做什么,那么我们可能能够为您提供更好的问题解决方案。

It has been said multiple times already, but you can make the tabs 2 and 3 disabled or not visible until the user clicks your submit button in tab1, validate the fileds, then enable tab2. The same can be done for tab3 if you have a submit button in tab2.

Again it needs to be reiterated that from a usability perspective this is not an optimal usage of tabs. If you tell us what the application is doing, then we would probably be able to give you a better solution to the problem.

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