2
我試圖構建一個新聞饋送應用程序,並且遇到格式化結果的麻煩,我確信這個問題只是缺乏經驗。第一個是item.summary.text拉過一連串的鏈接通過摘要C#RSS聚合,如何以編程方式格式化文本
我遇到的另一個問題是大膽所有的標題和改變它們的顏色我也使用豐富的文本框這可能不是代表數據的最佳方式。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ServiceModel.Syndication;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Xml.Linq;
using System.IO;
using System.Net;
using System.Xml;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Ltest1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string url = " http://feeds.reuters.com/reuters/topNews";
XmlReader reader = XmlReader.Create(url);
SyndicationFeed feed = SyndicationFeed.Load(reader);
reader.Close();
foreach (SyndicationItem item in feed.Items)
{
Fodder_Box.SelectionStart = "Title".Length;
Fodder_Box.SelectionColor = Color.Red;
Fodder_Box.SelectionFont = new Font("Arial", 20, FontStyle.Bold);
Fodder_Box.AppendText("Title: " + item.Title.Text + Environment.NewLine + Environment.NewLine);
Fodder_Box.SelectionStart = "Summary".Length;
Fodder_Box.SelectionColor = Color.Black;
Fodder_Box.SelectionFont = new Font("Arial", 20, FontStyle.Regular);
Fodder_Box.AppendText("Date: " + item.PublishDate.ToString("yyyy/MM/dd H:MM:ss") + Environment.NewLine + Environment.NewLine);
Fodder_Box.AppendText("Summary: " + item.Summary.Text + Environment.NewLine);
Fodder_Box.AppendText("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + Environment.NewLine + Environment.NewLine);
}
}
}
}
,完美的工作太感謝你了! –
沒問題,@Undead_Atomsk,請你可以標記爲答案...如果你真的喜歡它,你也可以投票,就像我爲你的問題所做的那樣;-) – davmos