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????
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????
Sorry, explain more..
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 ???
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")?
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<<<<<
ok I understand what you are doing, I will rack my brains for you hold on.....
if a user types "hello" then presses backspace to remove the "o" what would you like to happen then ? the label to read 4 ?
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 ?
Hello :
thanks a lot for your support , yes it must take 4....
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.
remember to declare ctr at the top of your class as such:
int ctr = 0;
Hello :
yes I have VS C#///
have you got the incrementor working yet ?
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.
Hello :
can you please re-write the final answer?? and what label2 for??
thanks in advance///
public partial class Form1 : Form
{
int ctr = 0;
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender,EventArgs e)
{
ctr++;
label1.Text = ctr.ToString();
}
}
label2 is what you need, label 1 was for testing.
that code i just posted will work
any joy ?
No, in text change event handler for the textbox let the label2.Text = textBox.Text.Length.ToString();
Thanks for all answers
nice one! was not aware of that !
No, in text change event handler for the textbox let the label2.Text = textBox.Text.Length.ToString();
ss
label1.Text = ctr.ToString(); this code shows label1 is out of context
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.