Controlling user workflow in Winforms(在 Winforms 中控制用户工作流程)
问题描述
我正在用 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.
我在第一个选项卡上有一个提交按钮,我希望在用户单击 submit
按钮时能够访问第二个选项卡.
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?
图片不可用
推荐答案
阻止用户选择选项卡会导致用户界面非常不直观.考虑创建一个向导",这是一个 UI 小工具,可通过下一步"按钮将用户从一个页面带到下一个页面.和一个后退按钮,可选.您可以通过设置 Next 按钮的 Enabled 属性来明确一个步骤已完成.
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.
可以使用 TabControl 创建这样的向导.向您的项目添加一个新类并粘贴如下所示的代码.编译.将新控件从工具箱顶部拖放到表单上.在设计时,它看起来像一个普通的 TC,允许您添加每个向导步骤所需的控件.在运行时选项卡是隐藏的.实现 Next 和 Back 按钮很简单,只需更改 SelectedIndex 属性即可.
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);
}
}
这篇关于在 Winforms 中控制用户工作流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Winforms 中控制用户工作流程
基础教程推荐
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- rabbitmq 的 REST API 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01