我正在开发一个 C# WinForms 应用程序。我找不到解决方案可能是因为我是新手。
我需要创建一个提词器,例如从底部滚动并循环上升的文本。有没有简单的解决方案或代码片段?
一个例子会很好,这样我就可以理解它是如何完成的。
这个想法是你可以使用计时器控件,处理它 Tick 事件
myTimer.Tick += new EventHandler(TimerEventProcessor);
Set myTimer.Interval = 1000;// event will fire every sec
private static void TimerEventProcessor(Object myObject,EventArgs myEventArgs) {
/// your logic to add new text, and change text position to give scroll effect
}
在 TimerEventProcessor 中,设置改变文本位置的逻辑,即改变它的 y 坐标,在底部添加新文本,这样你就可以创建滚动效果
在 timer.tick 事件处理程序中你可以做
if(label.Location.Y < 20)
label.Location = new Point(label.Location.X, this.ClientSize.Height);
else
label.Location = new Point(label.Location.X, label.Location.Y - 1);
希望这有帮助
您还可以创建一个带有文本的 Label 控件,并且只需每 1/20 秒左右将其垂直位置减少 1(以像素为单位)。