I have a html file which contains HTML formatted text. I want to display this text into a textbox in my c# wpf application. I'm using HTML Agility Pack to parse the text.
HtmlDocument HD = new HtmlDocument();
HD.LoadHtml(rangescenes.Text);
var root = HD.DocumentNode;
var sb = new StringBuilder();
foreach (var node in root.DescendantsAndSelf())
{
if (!node.HasChildNodes)
{
string text = node.InnerText;
sb.AppendLine(text);
}
}
Script = sb.ToString();
The result is that I get each line but I lose the layout. like padding and text-indent.
LOREM IPSUM DOLOR SITM AET 1
Lorem ipsum dolor sitm aet, consectetur adipiscing elit.
Phasellus et neque rhoncus, accumsan augue sit amet.
NAME
blablalbal blablabla blablablab
bla blablablablablalb blablalba
and I want to get this:
1 LOREM IPSUM DOLOR SITM AET 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Phasellus et neque rhoncus, accumsan augue sit amet.
NAME
blablalbal blablabla blablablab
bla blablablablablalb blablalba
Is there a way to display this HTML file in a textbox like a webbrowser would display the HTML file with padding and text-indent?
Solutions1
FIrst you need a hidden WebBrowser
Width="480" Height="480" Margin="2 2 2 2" >
and load you html in code behind.
myWebBrowser.NavigateToString(sb.ToString());
after you need copy and paste the content to your textbox.
myWebBrowser.Document.ExecCommand("SelectAll", false, null);
myWebBrowser.Document.ExecCommand("Copy", false, null);
yourTextBox.Paste();
I hope it helps!!