日期:2014-05-17  浏览次数:20696 次

c#键盘事件,为什么我的程序没反应
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 123
{
  public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  }
  private void Form1_KeyPress(object sender,KeyPressEventArgs e)
  {
  if (e.KeyChar == (char)Keys.Enter)
  label1.Text = "你按下了〈Enter〉键";  
  }

  }
}


------解决方案--------------------
用全局钩子 或者 在你所有的鼠标能点击到的控件上 都要加上监听