tags:

views:

93

answers:

2

I have a Label, whose content is displayed by a while loop. when i display a text in label, it displays correctly. sometime minutes, the same text displayed in the same label, and the size of the text in the control changes.

Here is the code :

//Form_Load :

Thread t = new Thread(displaySentences);
t.Start();


//display sentences:
void displaySentences()
{
    while(true)
    {
       if(i>=5)
          i=0;

       label4.Text = textarray[i];
       i++;

    }

}

the size of the text in the first iteration(i=0) is different from the size of the text in the label control in the second iteration.

+3  A: 

Do you not want autosizing? Set the autosize property to false.

Joel
A: 

I'd be looking for something elsewhere that was modifying properties on the label4 object.

Side note - should you really be spawning a thread and having that thread mess with the UI? Chris Sells wrote a series of articles in which he explained why this was a bad idea.

Adam V
I still can't solve my problems.
Attilah
I just copy/pasted your code into a Windows Forms app, and my side note is coming into play:"Cross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was created on."So unless you can post any additional information, or more code, or *something* that explains how you aren't getting this error, I don't know how to help you any more.
Adam V