TabControl 中自动跳到下一个 TabPage

发布于 2024-12-06 21:00:13 字数 273 浏览 0 评论 0原文

C# .Net fw 3.5,在TabControl中的winform中, 当用户从 TabPage 上的最后一个控件跳出时,焦点应该移动到下一页,并聚焦该页面中的第一个控件,我该怎么做?

这对我来说是必要的,因为在主条目表单中,有一些强制性问题被放置在 tabcontrol 之外,而一些控件并不是全部都在 tabcontrol 中,

如果用户顺序访问每个控件,那么焦点应该自动移动到下一个页面,如果用户只想填写必要的信息,那么他可以通过单击“保存”按钮提交。

对此有什么建议吗?

C# .Net fw 3.5, in winform in TabControl,
when the user tab out of the last control on a TabPage, then focus should moves to the next page, and focuses the first control in that page, how can i do it?

this is necessary for me because, in a master entry form, there is some compulsory questions which is placed out side of tabcontrol, and some controls which is not necessary all in tabcontrol,

if user visiting each control sequentially then focus should automatically move to next pages, if user want to fill only neccessory infos, then he can submit by clicking save button.

is any suggestion about this.

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

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

发布评论

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

评论(2

他夏了夏天 2024-12-13 21:00:13

你的问题不准确
“C# .Net fw 3.5,在winform中的TabControl中,当用户跳出TabPage上的最后一个控件时,焦点应该移动到下一页,并聚焦该页面中的第一个控件?”

这是一个陈述还是一个问题。我不明白。您需要的目标是什么?
如果您希望用户通过按 Tab 键来访问后续选项卡中的控件,您可以通过选项卡控件中的按键事件来完成。在按键事件中,您可以通过编程方式更改选项卡。
希望有帮助。

代码应该是这样的。
为您的选项卡控件生成按键事件并监视 TAB 键的按下。

    private void tabControl1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if(e.ToString().Equals("TAB") // I dont know what tab key returns. But is hould be something like this
        {
              tabControl1.SelectedTab = tabControl1.TabPages[1] ;
              // now tabpage 2 has the focus
              // You can also focus any control you want in here as follows:
              tabControl1.TabPages[1].Control["control key"].Focus();
        }
    }

希望它足够清楚

your question is not accurate
"C# .Net fw 3.5, in winform in TabControl, when the user tab out of the last control on a TabPage, then focus should moves to the next page, and focuses the first control in that page?"

is this a statement or question. I didnt understand. And what is the goal you need ?
If you want the user consequently visit the controls inside the consequent tabs by pressing tab key you can do it by keypressed event in tab control. In the keypressed event you can change the tab programatically.
hope it helps.

The code should be something like this.
Generate keypress event for your tabcontrol and monitor the press of TAB key.

    private void tabControl1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if(e.ToString().Equals("TAB") // I dont know what tab key returns. But is hould be something like this
        {
              tabControl1.SelectedTab = tabControl1.TabPages[1] ;
              // now tabpage 2 has the focus
              // You can also focus any control you want in here as follows:
              tabControl1.TabPages[1].Control["control key"].Focus();
        }
    }

hope its clear enough

万劫不复 2024-12-13 21:00:13
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;

namespace CSBSSWControls
{
    // Class inhertis TabControl
    public class bssTabControl : TabControl
    {
        private bool AutoTab_;
        [DefaultValue(false)]
        public bool AutoTab { get { return AutoTab_; } set { AutoTab_ = value; } }
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            //property which determines auto change tabpages
            if (AutoTab)
            {
                switch (keyData)
                {
                    case Keys.Tab | Keys.Shift:
                        {
                            return SetNextTab(false);
                        }
                    case Keys.Tab:
                        {
                            return SetNextTab(true);
                        }
                }
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
        private bool SetNextTab(bool Forward)
        {
            // getting cuurent active control
            ContainerControl CC = this.FindForm();
            Control ActC = null;
            while (CC != null)
            {
                ActC = CC.ActiveControl;
                CC = ActC as ContainerControl;
            }
            //checking, current control should not be tabcontrol or tabpage
            if (ActC != null && !(ActC is TabPage) && !(ActC is bssTabControl))
            {
                //getting current controls next control if it is tab page then current control is surely that last control on that tab page
                //if shift+tab pressed then checked its previous control, if it is tab page then current control is first control on the current tab page.
                TabPage NC = ActC.FindForm().GetNextControl(ActC, Forward) as TabPage;
                if (NC != null)
                    if (this.TabPages.Contains(NC))
                        if (Forward)
                        {
                            //selecting next tab page
                            this.SelectedTab = NC;
                            return true;
                        }
                        else
                        {
                            if (this.TabPages.IndexOf(NC) > 0)
                            {
                                //selecting pervious tab page
                                this.SelectedIndex = this.TabPages.IndexOf(NC) - 1;
                                return true;
                            }
                        }
            }
            return false;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;

namespace CSBSSWControls
{
    // Class inhertis TabControl
    public class bssTabControl : TabControl
    {
        private bool AutoTab_;
        [DefaultValue(false)]
        public bool AutoTab { get { return AutoTab_; } set { AutoTab_ = value; } }
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            //property which determines auto change tabpages
            if (AutoTab)
            {
                switch (keyData)
                {
                    case Keys.Tab | Keys.Shift:
                        {
                            return SetNextTab(false);
                        }
                    case Keys.Tab:
                        {
                            return SetNextTab(true);
                        }
                }
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
        private bool SetNextTab(bool Forward)
        {
            // getting cuurent active control
            ContainerControl CC = this.FindForm();
            Control ActC = null;
            while (CC != null)
            {
                ActC = CC.ActiveControl;
                CC = ActC as ContainerControl;
            }
            //checking, current control should not be tabcontrol or tabpage
            if (ActC != null && !(ActC is TabPage) && !(ActC is bssTabControl))
            {
                //getting current controls next control if it is tab page then current control is surely that last control on that tab page
                //if shift+tab pressed then checked its previous control, if it is tab page then current control is first control on the current tab page.
                TabPage NC = ActC.FindForm().GetNextControl(ActC, Forward) as TabPage;
                if (NC != null)
                    if (this.TabPages.Contains(NC))
                        if (Forward)
                        {
                            //selecting next tab page
                            this.SelectedTab = NC;
                            return true;
                        }
                        else
                        {
                            if (this.TabPages.IndexOf(NC) > 0)
                            {
                                //selecting pervious tab page
                                this.SelectedIndex = this.TabPages.IndexOf(NC) - 1;
                                return true;
                            }
                        }
            }
            return false;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文