2

我刚开始学习 VB 并尝试制作一个 WYSIWYG-HTML 编辑器。为此,我已经制作了一个 RichTextBox,用户可以在其中更改颜色、字体大小等。现在我想在一个以粗体书写的单词<b>之前添加一个 -Tag 和一个-Tag,将其保存在</b>字符串并在第二个只读文本框中返回新字符串。

最好的方法是什么?

4

1 回答 1

-1

所以你想将只读文本框的文本设置为richtextbox的文本,然后用其他字符串替换某些字符串?

如果是这样,这是我写的一些代码。这可能不是最好的,但它确实有效。

TextBox1.Text = RichTextBox1.Text 'Copies the text form the richtextbox to the normal textbox

    If TextBox1.Text.Contains("<b>") Then 'Checks to see if Textbox1 contains the string "<b>"
        TextBox1.Text = TextBox1.Text.Replace("<b>", "[b]") 'Replaces <b> with [b]
    End If

    If RichTextBox1.Text.Contains("</b>") Then 'Same thing as above but this checks to see if it contains "</b>"
        TextBox1.Text = TextBox1.Text.Replace("</b>", "[/b]")
    End If
于 2013-10-03T11:38:32.860 回答