i have a label
control in windows form
. i want to display full text in the label
. condition is like this:
- if text length exceeds more that 32 character than it will come in the new line.
if possible split by full word, without hyphen(-).
So far i have reach till below code:
private void Form1_Load(object sender, EventArgs e) { string strtext = "This is a very long text. this will come in one line.This is a very long text. this will come in one line."; if (strtext.Length > 32) { IEnumerable<string> strEnum = Split(strtext, 32); label1.Text =string.Join("-\n", strEnum); } } static IEnumerable<string> Split(string str, int chunkSize) { return Enumerable.Range(0, str.Length / chunkSize) .Select(i => str.Substring(i * chunkSize, chunkSize)); }
but issue is that the last line is not displaying entirely because its splitting by 32 character.
Is there another way to achieve this?