1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Tuesday, September 20, 2011

WPF RichTextBox Text and Font Extension Methods



using System.Drawing;
using System.Windows.Controls;
using System.Windows.Documents;

public static class ExtensionMethods
{
public static string GetText(this RichTextBox textBox)
{
TextRange textRange = new TextRange(textBox.Document.ContentStart, textBox.Document.ContentEnd);
return textRange.Text;
}

public static Font GetFont(this RichTextBox textBox)
{
FontFamily fontfam = new FontFamily(textBox.FontFamily.Source);
Font font = new Font(fontfam, (float)textBox.FontSize);
return font;
}

}