[英]Edit HTML in text edit field in C#
I have a text string with basic HTML tags like <b> <i> <ul> <ol>
tags.我有一个带有基本HTML 标签的文本字符串,例如
<b> <i> <ul> <ol>
标签。
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#?
我怎样才能在 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.现在我有一个
RichTextBox
但它在引擎盖下使用 RTF 标签而不是 HTML,所以我看到的不是格式化文本,而是 html 代码。
The easiest solution is using a WebBrowser
control, showing editable div:最简单的解决方案是使用
WebBrowser
控件,显示可编辑的 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.你还可以有一些工具栏按钮,用于设置文本粗体、斜体,或者插入
<ul>
或ol
等命令。 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:您可能还想看看以下帖子:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.