如何实现按F5  响应button1 事件???

解决方案 »

  1.   

    WINFORM??代码还是 思路??给个思路吧找到 BTN1的 键盘DOWN事件然后获取 键盘上的按键是F5的时候  委托 执行BTN1的CLICK事件
      

  2.   

    在KeyPress事件里面判断点击的是否是F5键,是的话执行button1事件
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication18
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show("我就是看看按F5行不行");
            }        private void Form1_KeyUp(object sender, KeyEventArgs e)
            {
                //判断是否按下的是F5
                if (e.KeyCode ==Keys.F5)
                {
                    //委托 增加BTN的点击事件
                    this.KeyUp +=new KeyEventHandler(button1_Click);
                    //相应的 去除BTN的点击事件 否则 连续按F5 会增加委托事件
                    this.KeyUp -= new KeyEventHandler(button1_Click);
                }
            }        private void Form1_Load(object sender, EventArgs e)
            {
                //Form 是否注册 键盘事件 默认为FALSE
                this.KeyPreview = true;
            }
        }
    }
      

  4.   

    2楼说的 是KEYDOWN 我下面是用的KEYUP
      

  5.   

    如果项目全局用的话注册热键比较好[DllImport("user32")]
            public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint control, Keys vk);        [DllImport("user32")]
            public static extern bool UnregisterHotKey(IntPtr hWnd, int id);        protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {
                    case 0x0312:
                        if (m.WParam.ToString() == "123")
                        {
                            this.Hide();
                        }
                        else if (m.WParam.ToString() == "456")
                        {
                            this.Visible = true;
                        }
                        break;
                }
                base.WndProc(ref m);        }        private void BookShelf_Load(object sender, EventArgs e)
            {
                //register:press [H] key to hide,and press [S] key to show
                RegisterHotKey(this.Handle, 123, 0, Keys.H);
                RegisterHotKey(this.Handle, 456, 0, Keys.S);
            }        private void BookShelf_FormClosed(object sender, FormClosedEventArgs e)
            {
                //unregister the hide/show hotkey
                UnregisterHotKey(this.Handle, 123);
                UnregisterHotKey(this.Handle, 456);
            }
      

  6.   

    用什么建不好,你怎么偏要去用F5,本来WINDOS就响应这个键了,换一个嘛