首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何检测C#窗口中的Ctrl +S?我的EventArgs没有`e.Modifiers`

如何检测C#窗口中的Ctrl +S?我的EventArgs没有`e.Modifiers`
EN

Stack Overflow用户
提问于 2014-10-14 12:57:16
回答 1查看 5.9K关注 0票数 0

这是我的第一个C# (也是第一个Windows)应用程序。我想对多键命令做出反应,但不知道怎么回事。web上的示例使用e.Modifierse.Controloverride bool ProcessCmdKey,其中没有一个选项出现在我的IDE中。我的主要课程是System.Windows.Window,所以这就是问题所在吗?我一直在读关于Forms的书--我在利用这个吗?

这是我的班级首页信息。

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
using System.Text;
using System.IO;
using System.Configuration;
using System.Threading.Tasks;
using System.Windows;
using Microsoft.WindowsAPICodePack.Dialogs;
//using System.Windows.Forms.
using Winforms = System.Windows.Forms;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Runtime.Serialization.Formatters.Binary;


namespace ContractCutter
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
...

这就是我尝试做事情的地方。我也只有Key类,而不是Keys类。

代码语言:javascript
复制
void CutContractKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.LeftCtrl)
                stuff;
        }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-14 13:09:57

你可以用这个:

代码语言:javascript
复制
private void CutContractKeyDown(object sender, KeyEventArgs e)
{
      if (e.Key == Key.S && Keyboard.Modifiers == ModifierKeys.Control)
     {
       MessageBox.Show("CTRL + S");
     }
}
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26361441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档