2017-04-14 14 views
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); 
      } 
     } 
    } 
} 

答えて

1

、あなたはのような、よりHTML優しいコントロールを使用することができますコントロール。次に、HTML文字列&をCSSでフォーマットすることができます。フォームにwebBrowserというWebBrowserコントロールを追加したとします。あなたはこのようなもので、あなたの現在のforeachループを置き換えることができます:

var text = new StringBuilder(); 

foreach (SyndicationItem item in feed.Items) 
{ 
    text.AppendFormat("<p style='font-family:arial;color:red;font-size:20;font-weight:bold;'>Title: {0}</p>", item.Title.Text); 
    text.AppendLine("</br>"); 
    text.AppendLine("</br>"); 

    text.AppendFormat("<p style='font-family:arial;font-size:20;'>Date: {0:yyyy/MM/dd H:MM:ss}</p>", item.PublishDate); 
    text.AppendLine("</br>"); 
    text.AppendLine("</br>"); 

    text.AppendFormat("<p style='font-family:arial;font-size:20;'>Summary: {0}</p>", item.Summary.Text); 
    text.AppendLine("</br>"); 
    text.AppendLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); 
    text.AppendLine("</br>"); 
    text.AppendLine("</br>"); 
} 

webBrowser.DocumentText = text.ToString(); 

また完全に働いたHow to: Add Web Browser Capabilities to a Windows Forms Application

+0

はそんなにありがとう参照してください! –

+0

問題はありません、@Undead_Atomsk、あなたは答えとしてマークしてください...あなたが本当にそれを好きだったなら、私はあなたの質問にしたようにアップ投票することもできます;-) – davmos

関連する問題