c#如何在winforms中创建类似应用程序的提词器?

时间:2011-05-02 11:27:07

标签: c# winforms scroll marquee

我正在开发一个C#WinForms应用程序。我找不到解决方案可能因为我是新人。

我需要创建一个类似于文本的提词器,它从底部滚动并循环上升。 有没有简单的解决方案或代码片段?

一个例子很好,这样我就可以理解它是如何完成的。

2 个答案:

答案 0 :(得分:1)

这个想法是你可以使用定时器控件,处理它的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);

希望这个帮助

答案 1 :(得分:1)

您还可以创建一个带文本的Label控件,只需每1/20秒左右将其垂直位置减1(以像素为单位)。