新闻行情从左到右移动文本 [英] News ticker with moving text from left to right
问题描述
我正在尝试制作一个将显示文本的rss新闻代码,文本需要从左向右移动
I am trying to make a rss news ticker which will display the text,the text need move from left to right
我使代码和文本从左向右移动,但在特定时间后未显示全文,我将添加更多来自管理员面板,每次我添加新闻后,第一次滚动后文本均不会显示
I made the the code and text is moving from left to right but after a specific time its not showing the full text,i will be adding more news from the admin pannel,each time i add the news the text is not showing after the first scroll
下面的屏幕截图是经过一定时间后,仅新闻的一部分正在显示
the below screenshot is after a specific amount of time,only a part of news is displaying
使用的代码
int x = -800,y=1;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
private void timer1_Tick(object sender, System.EventArgs e)
{
label1.SetBounds(x, y, 1, 1);
x++;
if(x>=800)
{
x = 4;
}
}
读取xml的代码
private void StartRssThread()
{
List<RssChannel> channels = new List<RssChannel>();
StringBuilder mergedFeed = new StringBuilder();
int mh = 0;
int ms = 0;
if (mh < 7)
{
RssFeed DaFeed = RssFeed.Read("http://shjc.ae/rss/fileName.xml");
RssChannel DaChannel = (RssChannel)DaFeed.Channels[0];
channels.Add(DaChannel);
mergedFeed.AppendFormat(" {0}: ", DaChannel.Title);
foreach (RssItem sTrm in DaChannel.Items)
{
if (ms < 10)
{
mergedFeed.AppendFormat(" {0} |", sTrm.Title);
ms++;
mh++;
}
}
}
string dafeed = mergedFeed.ToString();
mergedFeed = null;
textBox1.Invoke(new UpdateUiCallback(this.UpdateUi), new string[] { dafeed });
}
推荐答案
使用硬编码值作为x的起始值和最大值。根据您的问题,我认为标签中的文本具有动态长度(正确吗?)。如果文本的长度是动态的,则x的值也应该是动态的。
You are using hard coded values for the start and max value of x. From your question I think the text in the label has a dynamic length (correct?). If the text is of dynamic length the value of x should also be dynamic.
此外,x从-800开始。然后慢慢增长到800,然后将其设置为4。
对我来说,这很奇怪,如果第一次运行是在-800开始的,那么第二次运行可能也需要在-800开始。
Also, x starts at -800. Then slowly grows to 800 and then it gets set to 4. This seems strange to me, if the first run started at -800, the second run may also need to start at -800.
希望这对您有所帮助。如果没有,请提供更多详细信息(例如为什么选择-800、800和4)。
Hope this somewhat helped you. If not, please provide more details (like why you chose -800, 800 and 4).
这篇关于新闻行情从左到右移动文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!