如何在没有计时器的 Windows 窗体应用程序中制作移动新闻栏
我正在用 C# 制作一个桌面应用程序,其中包含一个移动的新闻栏标签。 我正在使用计时器来移动这些标签,但问题是,当我将该计时器的间隔设置得很低(例如 1-10)时,应用程序会占用非常高的 CPU 使用率,而当我将其设置得更高时(200 - 500)标签的移动变得间歇或不平滑,甚至用户可能无法以舒适的方式阅读新闻。
((更多信息)) 它是Windows窗体应用程序。我移动标签的方式如下:来自 RSS 提要的新闻项以一组链接标签表示。所有这些链接标签都添加到流程布局容器中。计时器移动整个流程布局容器。据我所知,我发现这种方式是制作新闻栏的最佳方式。如果您有更好的想法或解决方案,请帮忙。
I'm making a desktop application in C# which contains a moving News Bar labels.
I'm using a timer to move these labels but the problem is that when i make the interval of this timer low (1-10 for example) the application takes very high percentage of CPU Usage, And when i make it higher(200 -500 ) the movement of the labels becomes intermittent or not smooth movement even that the user may not be able to read the news in Comfortable way.
((More Information))
it is Windows form application. the way i move the labels is as follows : the news items from RSS feeds are represented in a group of linklabels. All these linklabels are added to a flowlayout container. The timer moves the whole flowlayout container. I found this way according to my knowledge the best way to making the news bar. If you have better idea or solution please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
定时器间隔代表什么?如果是毫秒,那么您可以将所需的每秒更新次数除以一千并获得计时器速率。
您也可以使用 Sleep(100) 左右,但这可能只是您在更新中尝试做太多事情。也许您可以少得多地进行“重要更改”,例如每 100 次更新左右,或者将这些更改放在自己的计时器上,并尽可能少地更新滚动,从而更频繁地更新滚动。
当您将应用程序设置为每秒更新 100 或 1000 次时,您的应用程序会占用大量 CPU,这并不奇怪。 :)
What does the timer interval represent? If it's milliseconds, then you can divide the number of updates per second that you want into one thousand and get the timer rate.
You could also use Sleep(100) or so, but it may just be that you're trying to do too much in your update. Maybe you can do "important changes" much less frequently, like only every 100 updates or so, or put those on their own timer, and do as little as possible to update the scrolling much more frequently.
It's not surprising that your application takes a lot of CPU when you have it set to do its update 100 or 1000 times per second. :)
我怀疑问题是您正在使用计时器来移动股票并填充数据?
如果你想使用计时器来滚动视图,那应该没问题。您的代码需要非常轻(只需更新垂直或水平位置并返回)。然而,更好的方法是使用类似“游戏循环”的东西来实现您想要的任何更新频率(在每次迭代中,计算移动视图所需的时间,然后休眠剩余的毫秒数)达到您的目标频率。)
从单独的计时器/线程更新数据。
I suspect the problem is that you're using the timer to move the ticker as well as populate the data?
If you want to use a timer to scroll the view, that should be fine. Your code needs to be extremely light (just update the vertical or horizontal positions and return). A better approach, however, would be to use something like a "game loop" to achieve whatever update frequency you're after (within each iteration, time how long it takes to move the view, then Sleep for the number of milliseconds remaining to hit your target frequency.)
Update the data from a separate timer/thread.
看:拖动一个标签和一个计时器
设置计时器间隔 = 100
然后 :
Look : Drag One Label and One Timer
Set Timer Interval = 100
then :
您可以创建一个自定义选取框标签,它使用计时器并重绘自身,并从左到右或从上到下对文本进行动画处理,如下所示 水平选取框标签或此垂直选取框标签。
但由于您询问的是没有计时器的问题,一个不错的选择是使用显示
marquee
标签,简单灵活。您可以为此设置任何内容、设置行为、方向、速度、外观、宽度、高度并完全自定义它。
示例
You can create a custom marquee label which uses a timer and redraw itself and animates the text from left to right or top to down, like this horizontal marquee label or this vertical marquee label.
But since you have asked about something without a timer, a good option is using a
WebBrowser
control showing amarquee
tag, easy and flexible.You can set any content for that, setup behavior, direction, speed, appearance, width, height and fully customize it.
Example