积极答复者
WPF 中的RictTextBox控件,如何在光标所在的位置插入文本,或者Hyperlink

问题
-
WPF 中的RictTextBox控件,如何在光标所在的位置插入文本,或者Hyperlink
- 已编辑 romantic william 2014年3月4日 11:37
- 已更改类型 Franklin ChenMicrosoft employee, Moderator 2014年3月5日 2:24 Question
答案
-
Hi,简单的代码如下,可以根据需要自行修改:
private void InsertText(RichTextBox tb, string text) { tb.CaretPosition.InsertTextInRun(text); } private void InsertHyperlink(RichTextBox tb, string text, string uri) { tb.Selection.Text = text; TextRange tr = new TextRange(tb.Selection.Start, tb.Selection.End); Hyperlink hlink = new Hyperlink(tr.Start, tr.End); hlink.NavigateUri = new Uri(uri); }
- 已建议为答案 Franklin ChenMicrosoft employee, Moderator 2014年3月5日 2:24
- 已标记为答案 Franklin ChenMicrosoft employee, Moderator 2014年3月12日 7:44
全部回复
-
Hi,简单的代码如下,可以根据需要自行修改:
private void InsertText(RichTextBox tb, string text) { tb.CaretPosition.InsertTextInRun(text); } private void InsertHyperlink(RichTextBox tb, string text, string uri) { tb.Selection.Text = text; TextRange tr = new TextRange(tb.Selection.Start, tb.Selection.End); Hyperlink hlink = new Hyperlink(tr.Start, tr.End); hlink.NavigateUri = new Uri(uri); }
- 已建议为答案 Franklin ChenMicrosoft employee, Moderator 2014年3月5日 2:24
- 已标记为答案 Franklin ChenMicrosoft employee, Moderator 2014年3月12日 7:44