0

I have dynamically created an array of labels. however, when i tried to set label.text = "hahaha hehehehe hmmmm", it displays only "hahaha" and not anything after the space.

for (int i = 0; i < labelArray.Length; i++)
{
    labelArray[i] = new Label();
    labelArray[i].BackColor = Color.Bisque;
    labelArray[i].Font = new Font(labelArray[i].Font.FontFamily, labelArray[i].Font.Size + 5, FontStyle.Bold);
    labelArray[i].Location = new Point(25, temp);
    labelArray[i].Name = "searchLabel" + i.ToString();
    labelArray[i].Text = "hahahahaha";
    labelArray[i].MouseEnter += new EventHandler(main_MouseEnter);
    labelArray[i].MouseLeave += new EventHandler(main_MouseLeave);
    searchPanel.Controls.Add(labelArray[i]);
    temp += 40; ;
}

have I missed out any anything? btw, this is the "initialization" done in Form_load and I edited the label.text in a TextChanged event. many thanks!

edit: I have since fixed the problem by setting autosize to true.

I have tried to display e.g. "hahahahahahahahaha hmmmmmm hehehehehehehehhe" and "ha hmmmmmmm hehehehehehhe" and in both cases only the first word gets displayed so I dont think it is being truncated..

the code which i used to set the text is simply:

labelArray[11].Text = "hahahahahahahahahaha eheheheheh hmmmmm";

3
  • 2
    That means, after hahahaha, you cannot do hehehe. Its not good for health :P Commented Sep 12, 2011 at 19:36
  • 1
    Can you post the code that adds the rest of the text? Commented Sep 12, 2011 at 19:38
  • Are you sure that it's cutting at the space? Have you tried setting the text to "ha ha" to see what happens? And are we talking about how it displays, or viewing the text in the debugger? Commented Sep 12, 2011 at 19:38

1 Answer 1

3

try setting AutoSize attribute to true

labelArray[i].AutoSize = true; 
Sign up to request clarification or add additional context in comments.

1 Comment

oh yes the autosize works! thank you thank you! shall go read the api for it right onw!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.