思路:
1.创建定时器每隔1秒触发事件
2.Label位置随时间变化
设置Label字体动态左右滚动
//设置 Label 字体左右滑动
public static void fontSlide(Label lab)
{
//初始化对象从右侧开始
lab.Location = new Point(lab.Parent.Width, lab.Location.Y);
Timer slideTimer = new Timer();
slideTimer.Enabled = true;
slideTimer.Interval = 100;
//鼠标放上去停止滚动
lab.MouseMove += new MouseEventHandler((s, x) =>
{
slideTimer.Enabled = false;
});
//鼠标离开继续滚动
lab.MouseLeave += new EventHandler((s, x) =>
{
slideTimer.Enabled = true;
});
//滚动
slideTimer.Tick += new EventHandler((s, x) =>
{
//如果当前标签定位已经完全滚动完了就恢复到右侧重新滚动
if (lab.Location.X <= (lab.Width - (lab.Width * 2)))
{
lab.Location = new Point(lab.Parent.Width, lab.Location.Y);
}
else
{
lab.Location = new Point(lab.Location.X - 10, lab.Location.Y);
}
});
}
亲测有效 欢迎点赞