1

I have a text string with basic HTML tags like <b> <i> <ul> <ol> tags.

Now I want to display it parsed in a editable text box and allow user to edit in a WYSIWYG way. How can I do it in C#?

Right now I have a RichTextBox but it uses RTF tags under the hood not HTML, so instead of formated text I see html code.

1 Answer 1

2

The easiest solution is using a WebBrowser control, showing editable div:

private void Form1_Load(object sender, EventArgs e)
{
    webBrowser1.DocumentText = @"
    <div contenteditable=""true"">
        This is a sample:
        <ul>
            <li>test</li>
            <li><b>test</b></li>
            <li><a href=""https://stackoverflow.com"">stackoverflow</a></li>
        </ul>
    </ div >";
}

You can also have some toolbar buttons for setting text bold, italic, or insert <ul> or ol and other commands. For example, the following command, makes the selection bold:

webBrowser1.Document.ExecCommand("Bold", false, null);

Or the following command inserts ordered list:

webBrowser1.Document.ExecCommand("InsertOrderedList", false, null);

You may also want to take a look at following post:

Windows Forms HTML Editor

Windows Forms HTML Editor

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. First item on your list is what I was looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.