English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I want to create a text counter in a way that when i type 3 letters in the text field the counter displays 3, and when i delete one the counter displays 2, thank you for your help

2006-12-13 02:43:47 · 4 answers · asked by moataz 1 in Computers & Internet Programming & Design

4 answers

hi.thats simple u can use it like that;

drag textbox(with multiline),label and timer onto your form

make timer's interval=1000(equals to 1 second).

then write a code like that to your timer_tick procedure

label1.Text = textBox1.Text.Length.ToString();

then write a code like that to your form_load procedure;

timer1.Enabled = true;

and run the project

it works fine with me.
Take care

by the way this example was made in c#.

2006-12-13 03:52:19 · answer #1 · answered by ibrahim ersoy 2 · 0 0

The way to do it is definitely via the OnChanged event for the textbox that the user will be typing in.

It's actually really simple, but just in case it'll be helpful for you, a code example:



Private Sub txtTypeArea_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTypeArea.TextChanged



'Using two textboxes...one called txtTypeArea to represent area user is typing in.
'the other called txtCount. txtCount is a read only textbox that stores the total
'number of characters typed as we go.



'Declare variable to hold number of characters typed

Dim NumberCount As Integer


'Set variable NumberCount equal to the length of the text string in txtTypeArea.

NumberCount = txtTypeArea.Text.Length


'Set the text value of txtCount equal to our NumberCount variable

txtCount.Text = NumberCount


'And then you're done...this code will fire every time the text changes, so your numbers
'will constantly update.

2006-12-13 13:46:32 · answer #2 · answered by poeticjustice72182 3 · 0 0

it depends on what type of application, in a window stand alone app, you can simply use the TextChanged event of the textbox to check the length of the textfield.

in a web app, you will need to do that via javascript, the same concept, access the form field and check its length on every keystroke.

2006-12-13 11:49:07 · answer #3 · answered by wl 1 · 1 0

take TextChanged event of your textbox



in another textbox you show the result of it:

_textChanged
txtResult.text = txtType.Text.Length

2006-12-13 12:03:29 · answer #4 · answered by holla 2 · 0 0

fedest.com, questions and answers