Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9170517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:02:02+00:00 2026-06-17T16:02:02+00:00

i have a label control in windows form . i want to display full

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:02:03+00:00Added an answer on June 17, 2026 at 4:02 pm

    I don’t know if you will accept an answer that doesn’t use linq, but this is simple:

    string SplitOnWholeWord(string toSplit, int maxLineLength)
    {
        StringBuilder sb = new StringBuilder();
        string[] parts = toSplit.Split();
        string line = string.Empty;
        foreach(string s in parts)
        {
            if(s.Length > 32)
            {
                string p = s;
                while(p.Length > 32)
                {
                    int addedChars = 32 - line.Length;
                    line = string.Join(" ", line, p.Substring(0, addedChars));
                    sb.AppendLine(line);
                    p = p.Substring(addedChars);
                    line = string.Empty;
                }
                line = p;
            }
            else
            {
                if(line.Length + s.Length > maxLineLength)
                {
                    sb.AppendLine(line);
                    line = string.Empty;
                }
                line = (line.Length > 0 ? string.Join(" ", line, s) : s);
            }
        }
        sb.Append(line.Trim());
        return sb.ToString();
    }
    

    Call with

    string result = SplitOnWholeWord(strtext, 32);
    

    It is possible to transform this in an extension method easily:

    Put the code above in a separate file and create a static class

    public static class StringExtensions
    {
         public static string SplitOnWholeWord(this string toSplit, int maxLineLength)
         {
              // same code as above.....
         }
    
    }
    

    and call it in this way:

    string result = strtext.SplitOnWholeWord(32);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a windows form with a label (or another control, i'm open to
I have a form with label that is updating by System.Windows.Forms.Timer control every 2
I have a control ...any System.Windows.Forms.Control . say for eg. label. I wish to
Say I have a label control in Winforms and I want to do some
i have a datalist control <ItemTemplate> <asp:Label ID=lblAddressID runat=server Text='<%# Bind(StudentName) %>'/> <asp:Label ID=lbl
I have a user control that contains multiple controls (CheckBox, Button, Label...). I want
I have a simple windows form with no border and several label controls (nothing
I use ASP.NET and have a label control on my page, which I fill
I have an updateprogress in my aspx file, which has a label control in
I have created a user control (link) which has a label and a button.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.