Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo, I have desctop application, i have some textbox and i must write some word in it and after click button something happen. Is there some method were i can find out, how many letters user write to textbox before he click button? For example he must write "hallo" and he write "halo", then he delete "o" and rewrite "lo" and then click button. So he write "hallo" but I want some method that will count, that he write totally 6 letters and dont 5 as is at textbox. Ty for Answer.
Posted

There is nothing standard to do that - we aren't generally interested in how a user entered the data, but what he ended up with.

You can do it: handle the KeyPress event for the TextBox and count the key presses:
C#
private int pressed = 0;
private void myTextBox_KeyPress(object sender, KeyPressEventArgs e)
    {
    if (char.IsLetterOrDigit(e.KeyChar))
        {
        pressed++;
        }
    }
 
Share this answer
 
Comments
Member 10808387 4-Mar-15 7:57am    
Thanks a lot. :)
Orcun Iyigun 5-Mar-15 8:08am    
I think I should give the exact solution to the OP to have my answer accepted as a solution :D
I think it is a WinForms application since you say desktop app. So there are some events that you can use KeyUp, KeyDown or KeyPress.

You can use KeyDown event and define a global or static variable that holds how many times it enters that event before that click button is pressed.

KeyDown Event MSDN[^]

Good luck,
OI
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900