C#标签的TabControl的切换 [英] C# Tab switching in TabControl

查看:1009
本文介绍了C#标签的TabControl的切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

荫面临这样的问题,我觉得这很难克服。在的WinForms我有n个TabPage一个TabControl。我想延长Ctrl + Tab键/按Ctrl + Shift + Tab键切换。所以我写了一些代码,只要罚款的重点是TabControl的或表上工作。当应用程序的重点是INSIDE的TabPage(例如其上放置TabPage的内部按钮),同时按下Ctrl + Tab键,我的代码将被忽略,TabControl的跳到他自己的TabPage(避免我的代码)。

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 some code which works fine as long as the focus is on TabControl or on the Form. When application focus is INSIDE of TabPage (for example on a button which is placed inside of TabPage), while pressing Ctrl+Tab, my code is ignored and TabControl skips to TabPage on his own (avoiding my code).

任何想法?

推荐答案

您需要从TabControl的派生和覆盖ProcessCmdKey,虚方法以覆盖Ctrl-Tab组合的行为。

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

例如:

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);
    }
}

这篇关于C#标签的TabControl的切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆