想实现的是用户按下键还未松开时只算作一次按键处理
(如果按下键还未松开,系统默认持续按键,如何只算作按键一次/)

解决方案 »

  1.   

    你可以使用让程序只接受OnKeyUp事件。
      

  2.   

    就是2楼的答案,在OnKeyUp事件里。
    这样的话,用户必须松开键才算完成一次按键操作。
      

  3.   

    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 WindowsFormsApplication29
    {
        public partial class Form1 : Form
        {
            Keys Old = Keys.None;         public Form1()
            {
                InitializeComponent();            TextBox TB = new TextBox();
                TB.Parent = this;            TB.KeyDown += new KeyEventHandler(TB_KeyDown);
                TB.KeyUp += new KeyEventHandler(TB_KeyUp);
            }        void TB_KeyUp(object sender, KeyEventArgs e)
            {
                Old = Keys.None;
            }        void TB_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyData == Old)
                    e.SuppressKeyPress = true;
                else
                    Old = e.KeyData;
            }
        }
    }