WinForm 實現文字滾動顯示


問題:系統登錄后,提示消息長度不固定,但空間有限

方案:用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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM