C#、WPF下实现普通快捷键的方法

来源:互联网 发布:java运用领域 编辑:程序博客网 时间:2024/04/30 12:19
普通快捷键只要在后台添加即可
代码如下
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;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.Shapes;namespace WpfDataGrid{    /// <summary>    /// Interaction logic for Window2.xaml    /// </summary>    public partial class Window2 : Window    {        public Window2()        {            InitializeComponent();            this.Loaded += new RoutedEventHandler(Window2_Loaded);        }        void Window2_Loaded(object sender, RoutedEventArgs e)        {            this.PreviewKeyDown += new KeyEventHandler(Window2_PreviewKeyDown);            button1.Click += new RoutedEventHandler(button1_Click);        }        void button1_Click(object sender, RoutedEventArgs e)        {            MainWindow main = new MainWindow();            main.ShowDialog();        }        void Window2_PreviewKeyDown(object sender, KeyEventArgs e)        {            if (e.Key == Key.F1)            {                button1_Click(this, null);            }        }    }}
本文来自CSDN博客,出处:http://blog.csdn.net/rose_liang/archive/2011/04/28/6369274.aspx
原创粉丝点击