首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c#键盘事件,为啥小弟我的程序没反应

2012-10-25 
c#键盘事件,为啥我的程序没反应using Systemusing System.Collections.Genericusing System.ComponentMo

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〉键";  
  }

  }
}
各位前辈帮我看看,谢了

[解决办法]

C# code
protected override void WndProc(ref Message m)        {            const int WM_HOTKEY = 0x0312;            if (m.Msg == WM_HOTKEY)            {                int id = m.WParam.ToInt32();                if (id == "注册热键的ID")            {                //响应程序            }            }            base.WndProc(ref m);        } /// <summary>        /// 注册热键        /// </summary>        /// <param name="fsModifiers"></param>        /// <param name="vk"></param>        /// <returns></returns>        public bool RegisterHotKey(int KeyId, uint fsModifiers, uint vk)        {            UnregisterHotKey(KeyId);            return Base.RegisterHotKey(this.Handle, KeyId, fsModifiers, vk);        }        /// <summary>        /// 注销热键        /// </summary>        /// <returns></returns>        public bool UnregisterHotKey(int KeyId)        {            return Base.UnregisterHotKey(this.Handle, KeyId);        }//注册热键 RegisterHotKey(text.keyId, (uint)text.wParam, (uint)text.lParam)//调用DLL        [DllImport("user32.dll")]        [return: MarshalAs(UnmanagedType.Bool)]        public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);        [DllImport("user32.dll")]        [return: MarshalAs(UnmanagedType.Bool)]        public static extern bool UnregisterHotKey(IntPtr hWnd, int id); 

热点排行