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 切换
基础教程推荐
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 从 C# 控制相机设备 2022-01-01
- 如果条件可以为空 2022-01-01
- 将数据集转换为列表 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
