【问题标题】:hyperlink inside the rich text box富文本框中的超链接
【发布时间】:2011-08-24 21:23:18
【问题描述】:

很抱歉为此创建一个新线程。

我有一个富文本框,我用来在富文本框中弹出我的 xml 数据。

我不知道如何超链接某些特定标签,对我来说,我需要在数据中超链接标签。

public void TEST(string message,string originalmessage)
    {
        txtOriginal.Text = originalmessage;
         richTextBox1.Text = message;
        this.ShowDialog();
    }

这里“消息”将 xml 作为字符串传递。

在此处应用 boby 代码后

public void TEST(string message,string originalmessage)
    {

    richTextBox1.Text = message;

    int startIndex = richTextBox1.Text.IndexOf("<Identifier>");
    int endIndex = startIndex + ("<Identifier>").Length - 3;
    richTextBox1.Select(startIndex, endIndex);
    richTextBox1.SelectionColor = Color.Blue;

    this.ShowDialog();
}

【问题讨论】:

  • 你确定 RTF 支持这个吗?

标签: c# richtextbox


【解决方案1】:

一种方法可能是。

页面加载中的this(例如)

richTextBox1.Text = "<TrainList><Header><Identifier>123457</Identifier></Header></TrainList>";
int startIndex = richTextBox1.Text.IndexOf("<Identifier>");
int endIndex = richTextBox1.Text.IndexOf("</Identifier>") + 13 - startIndex ;
richTextBox1.Select(startIndex, endIndex);
richTextBox1.SelectionColor = Color.Blue;

然后在点击事件中

private void richTextBox1_Click(object sender, EventArgs e)
{
  if (richTextBox1.SelectionColor == Color.Blue)
  {
     Process.Start("http://www.google.com");
  }
}

【讨论】:

  • 这条线是如何工作的? richTextBox1.Text = "你好吗" + 链接;
  • 我想像 richTextBox1.Text = message; 那样做吗?然后 int startIndex = richTextBox1.Text.IndexOf("");如有错误请指正
  • 在我上面的代码中,链接只是一个等于“Google”的字符串
  • 首先提取 标记之间的值,即如果它是 123456789,则上述代码中的变量链接将等于 123456789。然后您将拥有richTextBox1.Text .IndexOf("123456789");
  • 首先,我必须非常感谢才能让我到现在为止。看起来一切正常,但它会将颜色从 更改为一直到最后一个节点。我只是想仅颜色 123457 only.Any help please
猜你喜欢
  • 2012-04-08
  • 1970-01-01
  • 2015-04-20
  • 2015-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-22
  • 2012-10-13
相关资源
最近更新 更多