AvalonEdit插入文本不起作用

时间:2013-09-29 09:38:32

标签: c# text avalondock avalonedit icsharpcode

我无法在我的AvalonEdit TextEditor中插入一个字符。

void editor_TextArea_TextEntered(object sender, TextCompositionEventArgs e)
    {
        if (e.Text == "{" || e.Text == "(" || e.Text == "[" || e.Text == "\"" || e.Text == "\'")
        {
            switch (e.Text)
            {
                case "{":
                    int i = editor.TextArea.Caret.Offset;
                    editor.Text.Insert(i, "}");
                    break;
                case "(":
                    editor.Text.Insert(editor.CaretOffset, ")");
                    break;
                case "[":
                    editor.Text.Insert(editor.CaretOffset, "]");
                    break;
                case "\"":
                    editor.Text.Insert(editor.CaretOffset, "\"");
                    break;
                case "\'":
                    editor.Text.Insert(editor.CaretOffset, "\'");
                    break;
            }
        }
    }

我不知道它为什么不起作用。请帮帮我。

1 个答案:

答案 0 :(得分:6)

试试这个:

   editor.Document.Insert(editor.TextArea.Caret.Offset, "\'");