本文介绍了如何在WPF中捕获Ctrl + Tab和Ctrl + Shift + Tab?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将捕获 + 和 + + 用于WPF应用程序?

What would be some sample code that will trap the + and ++ for a WPF application?

我们创建了KeyDown事件,还尝试添加带有输入手势的命令绑定,但是我们永远无法捕获这两个快捷键.

We have created KeyDown events and also tried adding command bindings with input gestures, but we were never able to trap these two shortcuts.

推荐答案

您拥有什么KeyDown处理程序?下面的代码对我有用.给我带来麻烦的一个是: + ,但是您并没有要求:D

What KeyDown handler did you have? The code below works for me. The one that gives me trouble is: + , but you didn't ask for that :D

public Window1()
{
   InitializeComponent();
   AddHandler(Keyboard.KeyDownEvent, (KeyEventHandler)HandleKeyDownEvent);
}

private void HandleKeyDownEvent(object sender, KeyEventArgs e)
{
   if (e.Key == Key.Tab && (Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == (ModifierKeys.Control | ModifierKeys.Shift))
   {
      MessageBox.Show("CTRL + SHIFT + TAB trapped");
   }

   if (e.Key == Key.Tab && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
   {
      MessageBox.Show("CTRL + TAB trapped");
   }
}

这篇关于如何在WPF中捕获Ctrl + Tab和Ctrl + Shift + Tab?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 00:11