如何在没有计时器的 Windows 窗体应用程序中制作移动新闻栏 [英] How To Make Moving News Bar in Windows Forms Application without Timer

查看:28
本文介绍了如何在没有计时器的 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.

解决方案

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 a marquee tag, easy and flexible.

You can set any content for that, setup behavior, direction, speed, appearance, width, height and fully customize it.

Example

this.webBrowser1.DocumentText = @"
    <marquee>
    <span style='color:#f00;'>Breaking news: </span>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    </marquee>";

这篇关于如何在没有计时器的 Windows 窗体应用程序中制作移动新闻栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆