954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

text box input

Hello ALL:

In my form there is a textbox and label ,I want when I input a text when I'm inputting the first letter in the label value must be 1 if I input 2 letters in the label value it must be 2 ...etc...
Any idea????

aminit
Junior Poster in Training
78 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

Sorry, explain more..

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

Hello :

In textBox I must enter texts, this text it's contains of many letters, when I enter the first letter , (label) value(text) must be 1, when I enter 2 letters (label) text must be 2 and so on ???

aminit
Junior Poster in Training
78 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

do you mean
1.that if i type in "hello" in textbox, your label should reflect what has been typed (therefore the label text will be "hello")?
2.or do you mean that if I type in "hello"in to the textbox you want the label text set to "5" (because of five letters in "hello")?

majestic0110
Nearly a Posting Virtuoso
1,328 posts since Oct 2007
Reputation Points: 256
Solved Threads: 72
 

Hello :

Thanks a lot for your explain , actually yes I thinked of enter words ie(hello), and in the label text must be 5, but each letter when it's enter the label take values untill reach 5, for example when you enter h
the label must be 1 , and if you enter e(besides of h) the lable must be 2 and so on>>>>Thanks in advance<<<<

aminit
Junior Poster in Training
78 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

ok I understand what you are doing, I will rack my brains for you hold on.....

majestic0110
Nearly a Posting Virtuoso
1,328 posts since Oct 2007
Reputation Points: 256
Solved Threads: 72
 

if a user types "hello" then presses backspace to remove the "o" what would you like to happen then ? the label to read 4 ?

majestic0110
Nearly a Posting Virtuoso
1,328 posts since Oct 2007
Reputation Points: 256
Solved Threads: 72
 

ok you need to write some code in the textbox text changed event. (double click the textbox to make event hander) are you using Visual studio ?

majestic0110
Nearly a Posting Virtuoso
1,328 posts since Oct 2007
Reputation Points: 256
Solved Threads: 72
 

Hello :

thanks a lot for your support , yes it must take 4....

aminit
Junior Poster in Training
78 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

ok, well so far I have this:

ctr++;
            label1.Text= textBox1.Text;
            label2.Text = ctr.ToString();


This, however, doesnt reduce the label to 4 if a character is deleted. But im going to look at that now.

majestic0110
Nearly a Posting Virtuoso
1,328 posts since Oct 2007
Reputation Points: 256
Solved Threads: 72
 

remember to declare ctr at the top of your class as such:

int ctr = 0;
majestic0110
Nearly a Posting Virtuoso
1,328 posts since Oct 2007
Reputation Points: 256
Solved Threads: 72
 

Hello :
yes I have VS C#///

aminit
Junior Poster in Training
78 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

have you got the incrementor working yet ?

majestic0110
Nearly a Posting Virtuoso
1,328 posts since Oct 2007
Reputation Points: 256
Solved Threads: 72
 

what you need to do to get the label to say 4 or whatever is reduce the counter with this statement

ctr--


this needs to go in an event handler that is capable of detecting if the backspace is pressed. you see, a backspace is recognised as a character. hope this helps.

majestic0110
Nearly a Posting Virtuoso
1,328 posts since Oct 2007
Reputation Points: 256
Solved Threads: 72
 

Hello :
can you please re-write the final answer?? and what label2 for??
thanks in advance///

aminit
Junior Poster in Training
78 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 
public partial class Form1 : Form
    {
        int ctr = 0;
        public Form1()
        {
            InitializeComponent();
        }

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

        
    }
majestic0110
Nearly a Posting Virtuoso
1,328 posts since Oct 2007
Reputation Points: 256
Solved Threads: 72
 

label2 is what you need, label 1 was for testing.

majestic0110
Nearly a Posting Virtuoso
1,328 posts since Oct 2007
Reputation Points: 256
Solved Threads: 72
 

that code i just posted will work

majestic0110
Nearly a Posting Virtuoso
1,328 posts since Oct 2007
Reputation Points: 256
Solved Threads: 72
 

any joy ?

majestic0110
Nearly a Posting Virtuoso
1,328 posts since Oct 2007
Reputation Points: 256
Solved Threads: 72
 

No, in text change event handler for the textbox let the label2.Text = textBox.Text.Length.ToString();

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You