如何使用 vb.net 在 textarea 控件中为不同的句子涂上不同的颜色?

How can I color different sentences differently in a textarea control using vb.net?

我需要能够以编程方式 (vb.net) 定义文本区域中不同句子的颜色。我可以在表单应用程序中使用富文本框来完成此操作,但我需要能够在 Web 应用程序中执行此操作,并且我不需要大多数售后 asp.net 富文本编辑器的全部功能,只需简单地显示不同颜色的文本即可文字.

我试过一个文本框控件,它只能有一种颜色的文本。我尝试了一个 textarea 控件,但无法弄清楚如何使用 vb.net.

以编程方式更改文本颜色

Vb.net

Dim Sentence1 as string="This is what I have tried"

TextArea1.Value = Sentence1 & "Test Color"

我需要 Sentence1 为蓝色,"Test Color" 为红色,但我找不到 属性 来设置它。我尝试了 TextArea1.Forecolor、TextArea1.Color、TextArea1.Style 等,但似乎没有什么可以设置文本颜色。

vb.net 使用富文本框:

With RichTextBox1
        .SelectionColor = Color.Green
        .AppendText("hello ")
        .SelectionColor = Color.Red
        .AppendText("world")
End With

编辑: 对于 asp 和 textarea 的情况,这不是我的代码 btw:

假设,您在 aspx

处有以下布局
<div id="textarea">
<%=txt%>
</div>

然后在code-behind定义txt为

Protected txt As String

txt = "I look like textarea
<span style=""color:red"">some red text here</span>
<span style=""color:orange"">I have a basket of oranges</span>"

这应该以红色和橙色打印所需的文本。

也试试这个:txtdiv.innerhtml="Some normal text <span style='color: red;'>some red text</span>