Rich textbox that displays html like a web browser control - c#

I am displaying text in a rich textbox and i want it to show the html formatting on the text. Is there a way to make a rich textbox display html.
If you push the button on the following link you will see how my out put displays, i would like it done in a rich textbox.
http://neil.fraser.name/software/diff_match_patch/svn/trunk/demos/demo_diff.html
Is there a way to build a rich textbox that can display html???

RTF encoding is different from HTML.
If not, then you need to write your own HTML to RTF converter or find something similar.
Writing Your Own RTF Converter. This guy gives a great breakdown of how the program works along with details of the conversion.
An Extended richtextbox control, Check this out. It may solve your solution

Related

Getting Hyperlinks Working in Rich Text Box Using RTF

I am trying to format a hyperlink in a Rich Text Box using the Rich Text Format. I can get basic formatting working thanks to this answer, for example making text bold. However I cannot get the RTF formatted hyperlink to work. I found an example of making an RTF link here. However, when I try to put this in the Rich Text Box as seen below, it causes my application to crash. Any suggestions as to what i'm missing here?
string my_hyperlink_text = #"{\field{\*\fldinst HYPERLINK \"http://www.google.com/\"}{\fldrslt Google}}"
if (rtbControl is RichTextBox & rtbControl.Name == "name_of_control") // Making sure the control is a RichTextBox
{
RichTextBox rtb = rtbControl as RichTextBox;
rtb.Rtf = my_hyperlink_text;
}
An easy way for getting rtfs to work is to write your text in Microsoft word, copy & paste it to Wordpad and the saving it as a RTF from there.
The detour with MS Word is needed, because WordPad does not support entering links in the UI, although it handles them correctly when they come from other sources, like the clipboard. Also, MS Word creates massively bloated rtf.
The rtf file you create this way can then be opened in any text editor and can be used as a string constant in your program.
In your case, I suppose that the prefix and maybe the color table are missing and are causing the problem.
By the way: Wordpad is not much more than a wrapper around the Windows rtf control, i.e. the same control that you are using in your code.

How to lighlight link in text box

I have to create some controls similar to a control TextBox. But I want this control can Highlight link as RichTextBox, Because I have problem with RichTextBox so i can't use it. How do I highlight a link in a TextBox? or I have to set each property by a line of code?
I want to display it in a TextBox as shown below:
This is not possible. A simple TextBox control cannot be used to display formatted text.
A hyperlink is just specially formatted text: all it really does is change the foreground color to blue and the text style to underlined. TextBox controls don't allow this type of granularity. All text in the control has the same formatting applied to it.
What you would need to use is a RichTextBox control. This is specifically designed for displaying formatted text, and not only does it allow you to define arbitrary formatting for specific bits of text, but it has built-in support for detecting and highlighting hyperlinks. You say in your question that you had a "problem" with using the RichTextBox, so that is really the question that you should have been asking.

displaying email body as html in c# textbox

I am imitating my email client on a asp page. I have a gridview that displays things like from,subject,attachments, and the body. The body is html. When I view it in the grid view and set htmlencode= 'false' i can see it correctly. However, I want to the display it inside a textbox, so it can edit and forward it or reply.
Any ideas?
Thanks,
Load the HTML into a rich text editor to enable to user to edit it - be aware that most rich text editors out there are not designed to create email safe HTML and they will require a substantial amount of tweaking if you are going to support more than the most basic formatting.
Some example rich text editors:
http://ajaxcontroltoolkit.codeplex.com/
http://www.freetextbox.com/
Look into using a WYSIWYG (What You See Is What You Get) text editor like Cute Editor
you need to use an HTML Editor / TextBox, we use DevExpress components, very high quality but not free, there are also alternatives like Telerik or Infragistics and also free alternatives... see here: Best Free available wysiwyg html editor
Try this...
You can-t display html in textbox but you can get the source code.I am using this:) click here
You can try dinamycly add html code to page:
<div runat="server" id="myDiv">
</div>
and then set its InnerHtml property from the code-behind:
myDiv.InnerHtml = "your html here";
but with this way you cannot edit it...
if you are using Devexpress Controls,
you can use ASPxHTMLEditor.
It works exactly as your requirement is.

highlight a word in textarea in ASP.NET using C#

I have a TextArea control in my ASP.NET page which gets populated with a paragraph containing multiple sentences from the database. After this data gets populated in the TextArea control, I need to search for a few words in them and highlight them in different color. The words that I need to highlight are present inside a table in the database.
My question is : How do I highlight the selected words in a TextArea control using C#?
Please help. Thank you.
The HTML <textarea> tag doesn't contain the ability to add any text formatting. If you want to highlight a portion of your text, then you'll need to display it within a <div>, <span> or some other HTML element.
If you need to make the text editable and still highlight portions of it, then you could use a WYSIWYG HTML editor, such as the jHtmlArea Free, Open Source jQuery plugin.
Shameless Plug: jHtmlArea is a jQuery plugin I created a while back to fit a need I had for a light weight, easily extensible WYSIWYG HTML editor.
You can look into the DynaCloud jQuery plugin, or CodeMirror. Both provide some functionality for highlighting text.
http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
http://codemirror.net/

How do I paste richtext into a textbox?

I want to highlight some stuff on a web page and be able to paste it into a richtextbox in C# winforms. I want to then be able to see the HTML code of what I had pasted. Is this possible?
This snippet will return a string containing the code. There is some header info at the top that you may want to parse out but it is pretty straight forward.
string html = Clipboard.GetData(DataFormats.Html).ToString();
You will be able to populate that into a text box or richtext box however you like.

Categories