vb.net自动创建结束标记

时间:2014-03-11 08:40:13

标签: vb.net tags richtextbox

我想在vb.net中创建一个WYSIWIG html edditor,并且有一个丰富的文本框控件我试图为每个创建的开放标签自动创建结束标签,但不知道如何去做这个?

例如,如果用户键入htmy edditor将自动直接放在其下面

        Dim startingPoint As Integer = -1
    Do
        startingPoint = RichTextBox1.Find("<Body>", startingPoint + 1, RichTextBoxFinds.None)
        If (startingPoint >= 0) Then
            RichTextBox1.SelectionStart = startingPoint
            RichTextBox1.SelectionLength = "<Body>".Length
            RichTextBox1.SelectionColor = Color.Blue

            RichTextBox1.AppendText(Environment.NewLine & Environment.NewLine & "</Body>")

        End If
    Loop Until startingPoint < 0

1 个答案:

答案 0 :(得分:1)

我只是给你一个想法肯定你必须修改它,但我认为这会给你一个开始。

private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            string Text = richTextBox1.Text.Trim();
            int LastltIndex = Text.LastIndexOf('<');
            int LastgtIndex = Text.LastIndexOf('>');

            if ((LastltIndex < LastgtIndex) & LastltIndex != -1)
            {
                string Tag = Text.Substring(LastltIndex, (LastgtIndex - LastltIndex) + 1);
                richTextBox1.Text = richTextBox1.Text.Trim() + "\n" + Tag;
                richTextBox1.Select(richTextBox1.Text.Length, richTextBox1.Text.Length);
            }
        }