Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Var maxLength = (char) 10;
while(maxlength<Label.text)


Says can use < on operander like char and string Can somehelp mme=
Posted
Comments
Kishor Deshpande 21-Jan-13 11:06am    
Why you have put comparison in while?
It's wrong boolean operation by the way.

You can't compare a char with a string!
What you actuall want to say is:
C#
while (maxlength < myLabel.Text.Length)
Or more probably
C#
if (maxlength < myLabel.Text.Length)
 
Share this answer
 
You are using an operator on essentially a string value, which is not allowed. You need to declare your variables with a specific datatype. Your maxLength variable needs to be an int, not a char and Label.text needs to be Label.Text.Length.
 
Share this answer
 
Label does not have a maxlength property.
The best you can do is handle the keydown event and then ensure that the count is less than 10.

For e.g.
private label1_keydown(sender o, keydowneventargs a)
{
  if (label1.Length)>10 
  {
    label1.Text = label1.Text.SubString(0,10);
  }
}
 
Share this answer
 
Comments
Kurac1 21-Jan-13 15:50pm    
Hi its not working

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