我正面临这样的问题,我觉得很难克服.在 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 切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!