4

Im using a Label where text input from a text box is shown in that label. Now, I whant to make the label text scroll. I´ve looked around through the internet and I tried to write this into the code inside of the label:

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;
}

Does anybody see what Im doing wrong?

4

3 に答える 3

6

//はるかに簡単:

private void timer2scroll_Tick(object sender, EventArgs e)
{
  label10Info.Text = label10Info.Text.Substring(1, label10Info.Text.Length - 1) + label10Info.Text.Substring(0,1);
}
于 2014-11-11T17:32:41.457 に答える
2

関数呼び出しの外でスクロール変数を宣言する必要があります。クリックするたびにリセットされます。

ここでは、フォームの読み込み時にテキストを自動スクロールするタイマーを使用したコードを示します。

private Timer tmr;
private int scrll { get; set; }

void Form1_Load(object sender, EventArgs e)
{
    tmr = new Timer();
    tmr.Tick += new EventHandler(this.TimerTick);
    tmr.Interval = 200;
    tmr.Start();
}

private void TimerTick(object sender, EventArgs e)
{
    ScrollLabel();
}

private void ScrollLabel()
{
    string strString = "This is scrollable text...This is scrollable text...This is scrollable text";

    scrll = scrll + 1;
    int iLmt = strString.Length - scrll;
    if (iLmt < 20)
    {
        scrll = 0;
    }
    string str = strString.Substring(scrll, 20);
    label1.Text = str;
}

private void label1_Click(object sender, EventArgs e)
{
    ScrollLabel();
}
于 2012-12-06T09:18:32.210 に答える
0

これは、私のライブラリを使用して可能です。

WinForm アニメーション ライブラリ [.Net3.5+]

.Net WinForm (.Net 3.5 以降) でコントロール/値をアニメーション化するためのシンプルなライブラリ。キー フレーム (パス) ベースで完全にカスタマイズ可能。

https://falahati.github.io/WinFormAnimation/

    var textToScroll = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
    var durationOfAnimation = 5000ul;
    var maxLabelChars = 20;
    var label = label1;

    new Animator(new Path(0, 100, durationOfAnimation))
    {
        Repeat = true,
        ReverseRepeat = true
    }.Play(
        new SafeInvoker<float>(f =>
        {
            label.Text =
                textToScroll.Substring(
                    (int) Math.Max(Math.Ceiling((textToScroll.Length - maxLabelChars)/100f * f) - 1, 0),
                    maxLabelChars);
        }, label));
于 2016-05-19T22:55:17.413 に答える