C# Tab switching in TabControl(TabControl 中的 C# Tab 切换)
问题描述
我正面临这样的问题,我觉得很难克服.在 WinForms 中,我得到了一个带有 n 个 TabPages 的 TabControl.我想扩展 Ctrl+Tab/Ctrl+Shift+Tab 切换.所以我写了一些代码,只要焦点在 TabControl 或 Form 上就可以正常工作.当应用程序焦点位于 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);
}
}
这篇关于TabControl 中的 C# Tab 切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:TabControl 中的 C# Tab 切换


- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04