C# 为什么我使用变量t时它不';我什么也没展示?
我有以下格式1的代码:C# 为什么我使用变量t时它不';我什么也没展示?,c#,winforms,C#,Winforms,我有以下格式1的代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net; using
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Text.RegularExpressions;
namespace RssNews
{
public partial class Form1 : Form
{
string readableRss;
string t = "";
int counter;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
readableRss = RssReader.covertRss("http://rotter.net/rss/rotternews.xml");
string[] lines = Regex.Split(readableRss, "\r\n");
this.newsFeed1.NewsTextFeed = new string[lines.Length];
for (int i = 0; i < lines.Length; i++)
{
counter += 1;
if (counter <= 5)
{
t = Convert.ToString(lines[i]);
SetupText(new string[] { t,t,t,t,t });
}
else
{
counter = 0;
}
this.newsFeed1.TextColor = new Color[5];
SetupColors(new Color[] { Color.Blue, Color.Lime, Color.Maroon, Color.FromArgb(255, 71, 71, 255), Color.BurlyWood });
this.newsFeed1.Spacing = this.newsFeed1.Height;
this.newsFeed1.SetTexts();
this.newsFeed1.startFeed();
}
}
private void SetupColors(Color[] colors)
{
if (this.newsFeed1.TextColor.Length > 0 && colors.Length > 0)
this.newsFeed1.TextColor[0] = colors[0];
if (this.newsFeed1.TextColor.Length > 1 && colors.Length > 1)
this.newsFeed1.TextColor[1] = colors[1];
if (this.newsFeed1.TextColor.Length > 2 && colors.Length > 2)
this.newsFeed1.TextColor[2] = colors[2];
if (this.newsFeed1.TextColor.Length > 3 && colors.Length > 3)
this.newsFeed1.TextColor[3] = colors[3];
if (this.newsFeed1.TextColor.Length > 4 && colors.Length > 4)
this.newsFeed1.TextColor[4] = colors[4];
}
private void SetupText(string[] textToDisplay)
{
if (this.newsFeed1.NewsTextFeed.Length > 0 && textToDisplay.Length > 0)
this.newsFeed1.NewsTextFeed[0] = textToDisplay[0];
if (this.newsFeed1.NewsTextFeed.Length > 1 && textToDisplay.Length > 1)
this.newsFeed1.NewsTextFeed[1] = textToDisplay[1];
if (this.newsFeed1.NewsTextFeed.Length > 2 && textToDisplay.Length > 2)
this.newsFeed1.NewsTextFeed[2] = textToDisplay[2];
if (this.newsFeed1.NewsTextFeed.Length > 3 && textToDisplay.Length > 3)
this.newsFeed1.NewsTextFeed[3] = textToDisplay[3];
if (this.newsFeed1.NewsTextFeed.Length > 4 && textToDisplay.Length > 4)
this.newsFeed1.NewsTextFeed[4] = textToDisplay[4];
}
}
}
例如,ReadAbelss中的这部分内容:
סוף סוף: פורסמו הכרזים לבניה ברמת שלמה בי-ם
Mon, 27 Jan 2014 19:10:03 +0200
这两行应该是一块从下到上移动的文本
这就是我在台词中看到的:
在索引0中,我看到:“צ
在索引1中我看到:“2014年1月27日星期一19:18:39+0200”
现在这种情况下有151行
FOR循环中的变量t现在包含:
צפו: נפרד ממשפחתו ויוצא לבצע פיגוע התאבדות
在下一次迭代中,变量t包含:
Mon, 27 Jan 2014 19:18:39 +0200
我想要的是,一行的每一个文本以及它下面的下一行时间和日期将像动画中那样从下到上移动。
如果我使用我自己的文本和颜色,它将与我的代码一起工作,但我希望使用变量readableRss中的文本。由于使用文本
hi
而不是实际的字符串值,唯一的可能是ConvertRss
方法的输出仅返回换行字符或为空。您应该检查readableRss
变量
注意
t=Convert.ToString(第[i]行);
是无用的,因为行
是一个字符串数组
行
”是一个字符串数组
。为什么对字符串
使用转换.ToString
方法?你确定调用了设置文本
吗?你设置了断点吗?计数器初始化在哪里?1)显示是什么counter
2)显示readableRss
string的值3)显示SetupText
方法的实现4)显示t
被声明的位置用代码更新了我的问题,但代码有点长,但它都是连接的。此外,我还添加了使用断点时在变量中看到的内容添加到我的项目中,其设计器中的计时器设置为1000毫秒间隔。
צפו: נפרד ממשפחתו ויוצא לבצע פיגוע התאבדות
Mon, 27 Jan 2014 19:18:39 +0200