問題描述
我正在用 C# 構(gòu)建一個(gè) Winforms 應(yīng)用程序,并且我添加了一個(gè)具有三個(gè)選項(xiàng)卡的選項(xiàng)卡控件.
I'm building a Winforms application in C# and I have added a tab control that has three tabs.
我想限制用戶訪問第二個(gè)標(biāo)簽頁的能力,直到用戶填寫第一個(gè)標(biāo)簽頁.
I want to restrict user's ability to access the second tab page until user fills out the first tab.
我在第一個(gè)選項(xiàng)卡上有一個(gè)提交按鈕,我希望在用戶單擊 submit
按鈕時(shí)能夠訪問第二個(gè)選項(xiàng)卡.
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.
我怎樣才能做到這一點(diǎn)?
How can I accomplish this?
圖片不可用
推薦答案
阻止用戶選擇選項(xiàng)卡會(huì)導(dǎo)致用戶界面非常不直觀.考慮創(chuàng)建一個(gè)向?qū)?,這是一個(gè) UI 小工具,可通過下一步"按鈕將用戶從一個(gè)頁面帶到下一個(gè)頁面.和一個(gè)后退按鈕,可選.您可以通過設(shè)置 Next 按鈕的 Enabled 屬性來明確一個(gè)步驟已完成.
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 創(chuàng)建這樣的向?qū)?向您的項(xiàng)目添加一個(gè)新類并粘貼如下所示的代碼.編譯.將新控件從工具箱頂部拖放到表單上.在設(shè)計(jì)時(shí),它看起來像一個(gè)普通的 TC,允許您添加每個(gè)向?qū)Р襟E所需的控件.在運(yùn)行時(shí)選項(xiàng)卡是隱藏的.實(shí)現(xiàn) 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);
}
}
這篇關(guān)于在 Winforms 中控制用戶工作流程的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!