gpt4 book ai didi

c# - 如何将所选文本转换为 RichEditBox 中的超链接

转载 作者:行者123 更新时间:2023-11-30 20:32:19 24 4
gpt4 key购买 nike

我试过下面的代码,但它抛出异常System.ArgumentException,异常信息是:

Value does not fall within the expected range.

public void InsertLink(RichEditBox control) 
{
control.Document.Selection.Link ="http://www.bing.com";
}

最佳答案

The text it contains must be enclosed in quotes, optionally preceded by the sentinel character 0xFDDF. For example: "http://www.msn.com" or 0xFDDF"http://www.msn.com".

您可以从 MSDN source 获得更多详细信息.

因此您需要像下面这样更改您的代码:

<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<RichEditBox x:Name="richeditbox" Height="200">
</RichEditBox>
<Button Content="Convert to hypelink" Click="Button_Click"></Button>
</StackPanel>
private void Button_Click(object sender, RoutedEventArgs e)
{
richeditbox.Document.Selection.Link = "\"http://www.bing.com\"";
}

关于c# - 如何将所选文本转换为 RichEditBox 中的超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41717420/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com