C# WinForm中实现文字滚动显示

.Net技术 码拜 11年前 (2013-04-24) 5215次浏览 0个评论

开发中需要实现窗体文字滚动的效果。

思路:用Timer控件定时移动Label控件。父控件为Panel。详细代码如下:

 

privateSystem.Windows.Forms.TimertimeScroll;

/// <summary>

        /// 滚动步长

        /// </summary>

privateintpositon_falg =5;

/// <summary>

        /// 设置滚动内容字体 时间间隔 步长

        /// </summary>

        privatevoidScrollSet()

        {

            this.lbl_Scroll.Font=newFont(“宋体”,20,FontStyle.Regular);

            this.lbl_Scroll.Text = “滚动文字”;

            timeScroll = newSystem.Windows.Forms.Timer();

            timeScroll.Interval = 2000;

            timeScroll.Tick += newEventHandler(timeScroll_Tick);

            timeScroll.Start();

        }

        voidtimeScroll_Tick(objectsender, EventArgse)

        {

            if (this.lbl_Scroll.Location.X > 0 – this.lbl_Scroll.Width && this.lbl_Scroll.Location.X <= this.pl_Scroll.Width)

            {

                this.lbl_Scroll.Location = newPoint(this.lbl_Scroll.Location.Xpositon_falg, this.lbl_Scroll.Location.Y);

            }

            else

            {

                this.lbl_Scroll.Location = newPoint(this.pl_Scroll.Size.Width, this.lbl_Scroll.Location.Y);

            }

        }


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明C# WinForm中实现文字滚动显示
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!