0

Hi Everyone i am Making a Application that Scrolls Text On a Screen i Have this working with the small Exception that the long the text is vs certain font styles freeze/lag on the screen was wondering if someone has some insights on this

    void t_Tick(object sender, EventArgs e)
    {

        STimer t = sender as STimer;
        Label b = (Label)Controls[t.Name.Substring(1)];
        string sScrollText = b.Text;

        sScrollText = sScrollText.Substring(1,
            sScrollText.Length - 1) + sScrollText.Substring(0, 1);
        b.Text = sScrollText;

    }

That is the code that makes the label scroll example

100 Gerogia font with this text

In 1886, when prohibition laws were passed in some locations, John Pemberton developed Coca-Cola -- a non-alcoholic version of his previous French Wine Coca. Initially, Pemberton sold Coca-Cola as a patent medicine for 5 cents per glass near soda fountains; he claimed Coca-Cola could cure diseases like headache, morphine addiction, and impotence. Starting in 1894, Coca-Cola was starting to be sold in bottles, and advertised the product on outdoor walls

Fyi Random paragraph i found for testing

Runs Fine

100 Segoe Script

Freezes and Lags Horribly to the point you cannot close the program out

It Seems on Fonts that increase the physical size of the label to a large box freeze the program

Any Suggestions would be greatly appreciated

user3027738
  • 46
  • 1
  • 10

1 Answers1

0

Your problem is not really about the Fonts you use but about the AutoSize property of the Label.

Since you use a really long Text you seriously overrun its capacities.

You have two options to change:

  • You can set AutoSize = false and size the Label to a nice size, may even anchor it. You can use MeasureString to find out the Height you need to correct the LAbel's dimensions..

  • You can assign only a small part of the text, that doesn't stretch it out so immensly. You could use MeasureString to find an approximation of how many characters you can display and then add a little maybe or use a maximum width of pixels you want to allow..

BTW: There is even a maximum numer of pixels (around 30k) a Control may need to display its content before it 'gives up' and displays nothing at all. And right here different Fonts and FontSizes will make a difference..

Here is a way to adapt either the length of the part the text you want to display or the Label's Height after setting the Font:

using (Graphics G = label1.CreateGraphics() )
{
    // measure the size the label would need to display the text:
    SizeF size = G.MeasureString(sScrollText, label1.Font);

    // either restrict the text length:
    int maxWidth = 1600;
    len = (int) (sScrollText.Length * maxWidth / size.Width);

    // or set the Label's Height:
    label1.Height = (int) size.Height + 1;
}

BTW: The display will always look a little shaky since you are advancing by characters, which is neither smooth nor constant unless you choose a fixed font like Consolas. Painting on a per pixel-basis looks much better, but is a little more work, of course. Or one could move the Label inside a containing Panel to the left..

Community
  • 1
  • 1
TaW
  • 53,122
  • 8
  • 69
  • 111
  • Thanks i Used your method buy with minor mods, i set the max width to the screes max plus 1000 this allowed for the scrolling text to place its word out of sight to still give the scrolling effect – user3027738 Nov 26 '14 at 20:59