WPF RichTextBox Selection 属性错误?

发布于 2024-09-15 08:36:00 字数 370 浏览 0 评论 0原文

下一个代码工作完美(它仅更改选定文本的字体大小):

MyRichTextBox.Selection.ApplyPropertyValue(RichTextBox.FontSizeProperty, 18);

但是下一个代码更改整个文档的字体,而不仅仅是选定的文本:

var SelectedFont = new FontFamily("Tahoma");
MyRichTextBox.Selection.ApplyPropertyValue(RichTextBox.FontFamilyProperty, SelectedFont);

有人仅成功更改了选定的文本吗?如果是这样...怎么办?

The next code works perfectly (it changes the font size for -only- the selected text):

MyRichTextBox.Selection.ApplyPropertyValue(RichTextBox.FontSizeProperty, 18);

But the next code changes the font for the entire document, not only the selected text:

var SelectedFont = new FontFamily("Tahoma");
MyRichTextBox.Selection.ApplyPropertyValue(RichTextBox.FontFamilyProperty, SelectedFont);

Has anybody changed successfully only a selected text? if so... how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鯉魚旗 2024-09-22 08:36:00

就我而言,Visual Studio 中的默认 FontFamily 对于 Window 和 RichTextBox 也是 Tahoma。

尝试将 RichTextBox 默认 FontFamily 切换为 Georgia,并暂时将字体大小设置为 20,看看差异是否可见。

您的代码对我有用,就像使用 .NET 3.5 SP1 一样。

The default FontFamily in Visual Studio, in my case, is also Tahoma for both a Window and a RichTextBox.

Try switching your RichTextBox default FontFamily to Georgia, and temporarily make the font size 20 to see if the differences become visible.

Your code worked for me as is using .NET 3.5 SP1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文