繁体   English   中英

使用Label控件在c#winform中创建循环字幕文本

[英]using Label control to create looping marquee text in c# winform

我已经使用Label控件创建字幕文本,她是示例代码

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

但是当第一次完成时,它没有继续工作。请帮助我!

在timer1_Tick更改中

if (xPos == 0)

if (xPos <= 0)

否则,如果this.Width为奇数,它将不起作用。

我认为您需要检查xPos <=0。因为如果在xPos-= 2之后xPos = 1,则您的xPos将等于-1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM