gpt4 book ai didi

c# - 在 RichEditBox 中更改文本颜色

转载 作者:行者123 更新时间:2023-12-04 05:31:45 25 4
gpt4 key购买 nike

我在 Windows 8 中使用新的 RichEditBox 并尝试选择文本范围并更改文本颜色。下面的代码将添加下划线并更改所选文本的背景,但 ForegroundColor 不会更改,文本只是保持黑色。

result.Document.SetText(Windows.UI.Text.TextSetOptions.None, "Hello World");            
var range = result.Document.GetRange(0, 5);

range.CharacterFormat.Underline = Windows.UI.Text.UnderlineType.DoubleWave;
range.CharacterFormat.ForegroundColor = Windows.UI.Color.FromArgb(255, 0, 0, 255);
range.CharacterFormat.BackgroundColor = Windows.UI.Color.FromArgb(255, 0, 255, 0);

如何更改 RichEditBox 中的 ITextRange 的文本颜色?

最佳答案

您需要调用 Document.ApplyDisplayUpdates 来查看文本的更改。

result.Document.ApplyDisplayUpdates();

关于c# - 在 RichEditBox 中更改文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12486757/

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