C#在指定文本处添加链接

private void InsertLink(Point pt)
         {
             LinkLabel ll = new LinkLabel();
            ll.Text = "我的附件";
            ll.LinkClicked+=new LinkLabelLinkClickedEventHandler(linkLabel1_LinkClicked);
            //Point pt = new Point();
            //pt.X = 20;
            //pt.Y = 30;
            richTextBox1.Controls.Clear();
            ll.Location = pt;//设置linklable的位置
            this.richTextBox1.Controls.Add(ll);
         }
         private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
         {
             //Process.Start("iexplore", ((LinkLabel)sender).Text);
             MessageBox.Show("测试成功!!");
         }

         private void richTextBox1_TextChanged(object sender, EventArgs e)
         {
             Point pt = new Point();
             //int charIndex = richTextBox1.Find("指定文本") + 3;
             int charIndex =richTextBox1.Text.IndexOf("指定文本")+3;
             pt = richTextBox1.GetPositionFromCharIndex(charIndex);
             InsertLink(pt);
         }

你可能感兴趣的:(C#,链接,richTextBox,linklabe)