Friday 15 July 2011

c# - Keep "Backspace" key from being held down -


I am doing something similar to "Peter Answer", instead called "Adrian Answer", because of my name . But this is irrelevant, the question has already been answered, but I did not understand how it could implement my situation. I need a backspace key that can not be held. If you put it down, then it should only register once in the program, but not at any time after that. By the way, I want this feature in TextBox1. Peter answers here for reference

  using the 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 Peternensers {Public Partial Class} Form 1: Form {Public Form 1 () {Initial Group (); } Bool secret = false; String reply; String general = "adrian, please answer my question:"; Int i = 0; Bool secret2 = false; Private zero text box 1_kimpress (object sender, key events ages) {if (e. Cadata == key.opheriod & textbox1 text.length == 0) {i = 0; E.SuppressKeyPress = true; Secret = true; Textbox1.Text = = Normal [i]; Text box 1 Select (text box 1 text. Length, 0); I ++; Answer = Null; } And if (E. Kedata == key. Amporod & amp; Secret == true) {E. SuppressKeypress = true; Textbox1.Text = = Normal [i]; Secret = false; Text box 1 Select (text box 1 text. Length, 0); Secret2 = true; } And if (E.Kedata! = Keys. Omperiod & amp; Incognito == True & amp; amp; amp; E. Cadata! = Key. Back & amp; amp; Control.ModifierKeys! = Keys.Shift & amp; ; KeyData! = Keys.Space) {e.SuppressKeyPress = true; Answer + = E. Kedata; Textbox1.Text = = Normal [i]; Text box 1 Select (text box 1 text. Length, 0); I ++; } And if (E.Kedata == key.back & amp; secret == true) {string petition = text box 1. Text; If (petition! Lang! = 0) {if (petition> gender> 1) {petition = petition Delete (petition - Lang - 1); Answer = Answer Remove (Answer: Long-1); I--; } And if (Petition = Length == 1) {petition = petition. Remove (petition - length - 1); I--; Secret = false; Secret2 = false; Answer = Null; } And if (answer Lang> 0) {answer = answer.Remove (north. Length - 1); } And if (Answer Lang & lt; = 0) {answer = null; }}} And if (E. Kedata == key.Space and Covert == true) {e.SuppressKeyPress = true; Answer + = ""; Textbox1.Text = = Normal [i]; Text box 1 Select (text box 1 text. Length, 0); I ++; } And if (Control.ModifierKeys == Keys.Shift & Secret == true) {e.SuppressKeyPress = true; Text box 1 Select (text box 1 text. Length, 0); }} Private Zero Button 1_Click (Object Sender, EventArgs e) {If (Answer! = Null & Secret 2 == true) {answerLabel.Visible = true; Answer = System. threading. Thread Existing content Current agriculture Lesson Information. Troulecus (north toLower ()); AnswerLabel.Text + = "" + answer; } Else {Random RAND = New Random (); Switch (rand next (0, 4)) {case 1: answerLabel.Visible = true; AnswerLabel.Text + = "Sorry, can not answer the answer at the moment, please try again later."; break; Case 2: answerLabel.Visible = true; AnswerLabel.Text + = "Some seem to block my mental powers ..."; break; Case 3: answerLabel.Visible = true; AnswerLabel.Text + = "no answer."; break; Case 4: answerLabel.Visible = True; AnswerLabel.Text + = "I feel a lack of confidence ..."; break; }} Secret = false; Secret2 = false; } Private Zero Button 2_Click (Object Sender, EventArgs e) {i = 0; AnswerLabel.Visible = false; TextBox1.Clear (); TextBox2.Clear (); Answer = Null; Secret = false; Secret2 = false; AnswerLabel.Text = "Answer:"; Use a combination of  keydown ,      

key , and a boolean flag:
  private boolean_babpass = false; Private Zero Text box1_KeyDown (Object Sender, KeyEventArgs e) {if (e.KeyCode == Keys.Back) {e.SuppressKeyPress = _backspace; E.Handled = _backspace; _backspace = true; }} Private Zero Text Box 1_KeyUp (Object Sender, KeyEventArgs e) {if (e.KeyCode == Keys.Back) _backspace = false; }   

Flag only handler realizes that when the key has been placed and it is allowed again.

No comments:

Post a Comment