問題:系統登錄后,提示訊息長度不固定,但空間有限
方案:用Timer控制元件定時移動Label控制元件,父控制元件為Panel,
關鍵點:控制元件的Location屬性,是相對于容器的位置,
private int positon_flag = 1; private void timer_Tick(object sender, EventArgs e) { //當訊息內容小于容器長度,timer停止作業,文字固定 if (lac_loginName.Width <= panel7.Width- Math.Abs(lac_loginName.Location.X)) { timer.Stop(); } if (lac_loginName.Location.X > ( - lac_loginName.Width) && this.lac_loginName.Location.X <= this.lac_loginName.Width) { this.lac_loginName.Location = new Point(this.lac_loginName.Location.X - positon_flag, this.lac_loginName.Location.Y); } else { //當訊息尾移動到容器左邊緣,設定訊息坐標至容器最右側 this.lac_loginName.Location = new Point(panel7.Width, this.lac_loginName.Location.Y); } }
參考文章:https://www.codebye.com/winform-c-to-achieve-the-text-scrolling-display.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/300582.html
標籤:.NET技术
上一篇:.NET5修改配置不重啟自動生效
下一篇:.NET5修改配置不重啟自動生效
