开发者

WPF RichTextBox Selection property bug?

开发者 https://www.devze.com 2023-01-12 03:04 出处:网络
The next code works perfectly (it changes the font size for 开发者_StackOverflow中文版-only- the selected text):

The next code works perfectly (it changes the font size for 开发者_StackOverflow中文版-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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消