标签滚动效果

Jes*_*pez 4 c# label scroll winforms

我使用一个标签,其中从文本框中输入的文本显示在该标签中。现在,我想让标签文本滚动。我通过互联网环顾四周,并尝试将其写入标签内的代码中:

private void label1_Click(object sender, EventArgs e)
{
    int Scroll;
    string strString = "This is scrollable text...This is scrollable text...This is scrollable text";

    Scroll = Scroll + 1;
    int iLmt = strString.Length - Scroll;
    if (iLmt < 20)
    {
        Scroll = 0;
    }
    string str = strString.Substring(Scroll, 20);
    label1.Text = str;
}
Run Code Online (Sandbox Code Playgroud)

有没有人看到我做错了什么?

小智 6

//更容易:

private void timer2scroll_Tick(object sender, EventArgs e)
{
  label10Info.Text = label10Info.Text.Substring(1, label10Info.Text.Length - 1) + label10Info.Text.Substring(0,1);
}
Run Code Online (Sandbox Code Playgroud)

  • 虽然此代码片段可能会解决问题,但 [包括解释](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) 确实有助于提高帖子的质量。请记住,您是在为将来的读者回答问题,而那些人可能不知道您提出代码建议的原因。 (3认同)