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