C# Tab switching in TabControl

后端 未结 2 890
一整个雨季
一整个雨季 2020-12-21 05:32

Iam facing such problem, which I find hard to overcome. In WinForms I got a TabControl with n TabPages. I want to extend the Ctrl+Tab / Ctrl+Shift+Tab switching. so I wrote

2条回答
  •  醉酒成梦
    2020-12-21 06:02

    You need to derive from TabControl and override ProcessCmdKey, virtual method in order to override the Ctrl-Tab behavior.

    Example:

    public class ExtendedTabControl: TabControl
    {
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control | Keys.Tab))
            {
                // Write custom logic here
                return true;
            }
            if (keyData == (Keys.Control | Keys.Shift | Keys.Tab))
            {
                // Write custom logic here, for backward switching
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
    }
    

提交回复
热议问题