1

C# .Net fw 3.5、TabControl の winform で、ユーザーが TabPage の最後のコントロールからタブを外すと、フォーカスが次のページに移動し、そのページの最初のコントロールにフォーカスする必要があります。どうすればよいですか?

マスター入力フォームでは、タブコントロールの外側に配置される必須の質問と、すべてタブコントロール内にある必要のないコントロールがあるため、これが必要です。

ユーザーが各コントロールに順番にアクセスすると、フォーカスは自動的に次のページに移動し、ユーザーが必要な情報のみを入力したい場合は、保存ボタンをクリックして送信できます。

これについての提案です。

4

2 に答える 2

1
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;
        }
    }
}
于 2011-09-28T06:49:14.923 に答える
1

あなたの質問は正確ではありません。

これは声明ですか、それとも質問ですか。理解できませんでした。そして、あなたが必要とする目標は何ですか?ユーザーが結果的にタブキーを押して結果タブ内のコントロールにアクセスしたい場合は、タブコントロールの keypressed イベントでそれを行うことができます。keypressed イベントでは、タブをプログラムで変更できます。それが役に立てば幸い。

コードは次のようになります。タブ コントロールの keypress イベントを生成し、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();
        }
    }

十分に明確であることを願っています

于 2011-09-27T12:10:49.227 に答える