views:

24

answers:

1

Hi. 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?

A: 

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.

Zamboni
The "Tahoma" was just an example. In .NET 4.0 it does not change the font for the selected text, it changed for the whole doc.
Néstor Sánchez A.
Solved: It was a binding in the base class of my custom richt-text editor. Thanks!
Néstor Sánchez A.