Click here to Skip to main content
15,891,002 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hallo, I have question, 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. Ty for Answer.
Posted
Comments
Maciej Los 1-Mar-15 12:19pm    
What have you tried? Where are you stuck?
Santosh K. Tripathi 1-Mar-15 22:52pm    
Is it web application or desktop application?
Member 10808387 4-Mar-15 6:53am    
It is desktop application, i tried something like one of solution below but it couts characters and don't letters as I need

If your application is Desktop Application then you can use lostfocus of the textbox

C#
private void textBox1_LostFocus(object sender, System.EventArgs e)
	{
		// get word count of textbox1.text  
                // perhaps you can remove spaces , then get it's length
	}


If it is web project then, text box is an input with type text or it is textarea.

you can assign handler for onBlur event and then remove spaces , then get it's length in javascript.
 
Share this answer
 
v2
Maybe this will work for you.

Here is a simple Windows Form Application.

On my form I have 3 elements:

1) a Textbox named textbox1
2) a Label named label1
3) a Button named Button1

Below shows how I setup the textbox1.TextChanged and button1_click.

As you enter text into the textbox, the label will show how many characters are in the textbox. If you backspace or delete any, the count will change.

If the count does not = 6 when you click the button, it does NOTHING.
However, if it DOES = 6, then it changes the label to say "OK"

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            label1.Text = textBox1.TextLength.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt32(label1.Text) != 6)
            {
                // Do nothing Not 6 charaters
            }
            else
            {
                label1.Text = "OK";
            }
        }
    }
}


Hope this helps!
 
Share this answer
 
Comments
HKHerron 1-Mar-15 12:09pm    
This will count spaces as a character!

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