winforms - C# RSS Syndication, How to format text programmatically -


i"m trying build news feed application , i'm having trouble formatting results. i'm sure issue lack of experience. there 2 main issues i'm having. first item.summary.text pulls bunch of links past summary.

the other issue i'm having bold titles , change color. i'm using rich text box not best way represent data.

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);             }         }     } } 

instead of richtextbox, use control more html friendly webbrowser control. can build html string & format css. let's add webbrowser control named webbrowser form. replace current foreach loop this:

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(); 

also see how to: add web browser capabilities windows forms application


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -