Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在RichTextBox的光标位置插入字符串_C#_String_Richtextbox - Fatal编程技术网

C# 在RichTextBox的光标位置插入字符串

C# 在RichTextBox的光标位置插入字符串,c#,string,richtextbox,C#,String,Richtextbox,我正在尝试在光标位置插入字符串。。我正在写一个语法高亮控件,我想做一个函数,这样用户可以注释掉一行代码。“//blah”所有这些操作都将插入指定的注释标识符 richTextBox.GetCharIndexFromPosition(Point point) 将为您提供字符索引 另一种可以帮助您的方法: richTextBox.GetFirstCharIndexFromLine(int lineNumber); richTextBox.GetFirstCharIndexOfCurrentLine

我正在尝试在光标位置插入字符串。。我正在写一个语法高亮控件,我想做一个函数,这样用户可以注释掉一行代码。“//blah”所有这些操作都将插入指定的注释标识符

richTextBox.GetCharIndexFromPosition(Point point)
将为您提供字符索引

另一种可以帮助您的方法:

richTextBox.GetFirstCharIndexFromLine(int lineNumber);
richTextBox.GetFirstCharIndexOfCurrentLine();
richTextBox.GetLineFromCharIndex(int index);
richTextBox1.SelectionLength = 0;
richTextBox1.SelectedText = "//";