• C# 跑马灯效果




    using
    System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using Timer = System.Timers.Timer; namespace WindowsFormsApp1.Frm { /// <summary> /// 跑马灯 /// </summary> public partial class RunHorse : Form { private static Timer timer = new Timer(); public RunHourse() { InitializeComponent(); timer.Interval = 50; } private void RunHorse_Load(object sender, EventArgs e) { timer.Elapsed += Timer_Elapsed; //初始化lbl位置 { var pWidth = this.panel1.Width; this.label1.Left = pWidth; this.label2.Left = pWidth; } //初始化lbl位置 { var pWidth = this.panel2.Width; this.label3.Left = pWidth; this.label4.Left = pWidth; } timer.Start(); } private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { try { timer.Stop(); //循环跑 this.panel1.InvokeOnUiThreadIfRequired(() => { var pWidth = this.panel1.Width; ; //lbl2准备好了,且lbl1还没跑完 if (this.label2.Left == this.panel1.Width && this.label1.Right > 0) this.label1.Left -= 10; else this.label1.Left = pWidth; //lbl1准备好了,且lbl2还没跑完 if (this.label1.Left == this.panel1.Width && this.label2.Right > 0) this.label2.Left -= 10; else this.label2.Left = pWidth; }); //即将结束时开始下一个 this.panel2.InvokeOnUiThreadIfRequired(() => { var pWidth = this.panel2.Width; if (this.label3.Right < 0) this.label3.Left = pWidth; if (this.label4.Right < 0) this.label4.Left = pWidth; //lbl1即将消失,且 lbl2准备好了 if (this.label3.Right < 80 && this.label4.Right > 0) { this.label3.Left -= 10; this.label4.Left -= 10; } //lbl2即将消失,且 lbl1准备好了 if (this.label4.Right < 80 && this.label3.Right > 0) { this.label3.Left -= 10; this.label4.Left -= 10; } //lbl2准备好了,且lbl1还没跑完 if (this.label4.Left == pWidth && this.label3.Right > 0) this.label3.Left -= 10; //lbl1准备好了,且lbl2还没跑完 if (this.label3.Left == pWidth && this.label4.Right > 0) this.label4.Left -= 10; }); } catch (Exception ex) { Console.WriteLine(ex + ""); } finally { timer.Start(); } } private void button1_Click(object sender, EventArgs e) { this.label1.Text = "0123456789"; } private void button2_Click(object sender, EventArgs e) { this.label2.Text = "ABCDEFGHIJK"; } } }
  • 相关阅读:
    图灵访谈之二十二——Brian W. Kernighan与CS的半个世纪 (翻译)
    GIT 初探
    关于SQL的分组汇总统计(关键字 Grouping)
    根据表名生成该表的插入语句
    利用sys.dm_db_index_physical_stats查看索引碎片等数据
    SQL SERVER CURSOR
    Configuring a readonly replicated folder on Windows Server 2008 R2.
    securestring
    Sql Server查询性能优化
    七大排序速查版
  • 原文地址:https://www.cnblogs.com/huawublog/p/12639447.html
Copyright © 2020-2023  润新知