簡體   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