Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all, can anyone tel me how to keep limited no. of text in a label...my text in the Lbl will change dynamically based on timer like a stopwatch..so pls clear me this issue..




Thnks & Regards,
Ahn
Posted

1 solution

This should do it:
If you want to keep only 5 characters in your label, then,

C#
private void Timer1_tick(object sender, EventArgs e)
{
if(Label.Text.Length >5)//if length is greater than 5
{
//get length of characters to be removed from Label text
int removelength= Label.Text.Length - 5;
//Remove characters greater than 5 at 5th index of character in label
Label1.Text = Label.Text.Remove(5 , removelength); //syntax: Remove(index, length);
}
}
 
Share this answer
 
v4

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