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

button的触发事件Key_Down和KeyPress出现问题

这三个是效果图
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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        bool flag = false;
        public Form1()
        {
            InitializeComponent();
            button1.KeyPress+=new KeyPressEventHandler(button_KeyPress);
            button2.KeyPress+=new KeyPressEventHandler(button_KeyPress);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (flag == false)
            {
                label1.Text = "Good  Night";
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (flag == false)
            {
                label1.Text = "Good Afternoon";
            }
        }
        private void button_KeyPress(object sender,KeyPressEventArgs e)
        {
            flag = false;
            if (32 == e.KeyChar)