使用标签控件创建在C#的winform循环滚动字幕文本控件、字幕、文本、标签

2023-09-04 06:13:42 作者:深情迎风散

我一直在用Label控件创建滚动字幕文本她是样品​​code

I have been create Marquee text using Label control her is sample code

public partial class FrmMarqueeText : Form
{
    private int xPos = 0, YPos = 0;

    public FrmMarqueeText()
    {
        InitializeComponent();
    }

    private void FrmMarqueeText_Load(object sender, EventArgs e)
    {

            lblText.Text = "Hello this is marquee text";
            xPos = lblText.Location.X;
            YPos = lblText.Location.Y;
            timer1.Start();


    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        if (xPos == 0)
        {

            this.lblText.Location = new System.Drawing.Point(this.Width, YPos);
            xPos = this.Width;
        }
        else
        {
            this.lblText.Location = new System.Drawing.Point(xPos, YPos);
            xPos -= 2;
        }
    }

但是当第一次结束了,但它并没有继续工作。请帮帮我!

but when the first time was finished, it didn't continues work .Please help me!

推荐答案

在timer1_Tick变化

In timer1_Tick change

if (xPos == 0)

if (xPos <= 0)

否则将无法工作,如果 this.Width 是奇数。