您的位置:首页 > 编程语言 > C#

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

2012-04-05 02:05 176 查看
普通快捷键只要在后台添加即可

代码如下
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: