RichTextBox中的自定义链接假设我想让每个以#开头的单词在被双击时产生一个事件。为此,我发现了以下测试代码:privateboolIsChannel(Pointposition,outintstart,outintend){if(richTextBox1.Text.Length==0){start=end=-1;返回假;}intindex=richTextBox1.GetCharIndexFromPosition(position);int停止=索引;while(index>=0&&richTextBox1.Text[index]!='#'){if(richTextBox1.Text[index]==''){break;}-指数;}if(index<0||richTextBox1.Text[index]!='#'){start=end=-1;返回假;}while(stopcharPoint.X+richTextBox1.Font.SizeInPoints);如果(notOnTheSameLine||passedTheWord){开始=结束=-1;返回假;}//获取客户端坐标中的鼠标点PointclientPoint=richTextBox1.PointToClient(richTextBox1.PointToScreen(position));intindex=richTextBox1.GetCharIndexFromPosition(位置);//获取最近的charPoint的位置charPoint=richTextBox1.GetPositionFromCharIndex(index);boolnotOnTheSameLine=((clientPoint.YcharPoint.Y+richTextBox1.Font.Height));boolpassedTheWord=(clientPoint.X>charPoint.X+richTextBox1.Font.SizeInPoints);如果(notOnTheSameLine||passedTheWord){开始=结束=-1;返回假;对于第(1)点,也许有不同的方式来跟踪链接而不是dbl-click?也许cntl-click会避免单词被选中的问题...以上就是C#学习教程:RichTextBox中自定义链接分享的全部内容。如果对大家有用,需要进一步了解C#学习教程,还望大家多加关注——本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如有转载请注明出处: