Some Alt keys changes my RichTextBox font

This is the default behavior. The RichTextBox Control automatically finds a fallback font to represent characters that the current Font can’t handle. If not otherwise instructed, it changes the Font selection with the fallback Font. Read this rant about the same default behavior of the RichTextBox ancestor (the RichEdit / MsftEdit Control, from which the … Read more

C# – Loading a large file into a WPF RichTextBox?

WPF RichTextBox control use Flow Document to display Rich Text and then attach the Flow Document to RTB control,while Windows Form RichTextBox control display Rich Text directly. that’s what makes WPF RTB super slow. if you are okay with using a WinForm RTB just host it in your wpf app. the xaml : <Window x:Class=”WpfHostWfRTB.MainWindow” … Read more

RichTextBox Newline Conversion?

The RichTextBox.Text property is converting the assigned string into an rtf document according to the Rtf format codes specified in the RichTextBox.Rtf property. Since the ‘rtb’ instance is not being initialized the ‘Rtf’ format codes are empty, and it’s just echoing back your input. After ‘rtb’ is initialized it contains an empty rtf document (with … Read more

How to append \line into RTF using RichTextBox control

Adding a Unicode “Line Separator” (U+2028) does work as far as my testing showed: private void Form_Load(object sender, EventArgs e) { richText.AppendText(“Hello, World!\u2028”); richText.AppendText(“Hello, World!\u2028”); string rtf = richText.Rtf; richText.AppendText(rtf); } When I run the program, I get: Hello, World! Hello, World! {\rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fnil\fcharset0 Courier New;}} {\colortbl ;\red255\green255\blue255;} \viewkind4\uc1\pard\cf1\f0\fs17 Hello, World!\line Hello, World!\line\par } It did … Read more

C# RichEditBox has extremely slow performance (4 minutes loading)

I downloaded the sourcecode of Wordpad (http://download.microsoft.com/download/4/0/9/40946FEC-EE5C-48C2-8750-B0F8DA1C99A8/MFC/ole/wordpad.zip.exe) and it has the same worst performance (4 minutes). But this sample is an old version of Wordpad. So Microsoft has improved anything in Wordpad in the last years that is missing in the .NET framework. Finally I found the solution: The .NET framework uses the RichEdit20W class … Read more

How do you prevent a RichTextBox from refreshing its display?

Here is complete and working example: private const int WM_USER = 0x0400; private const int EM_SETEVENTMASK = (WM_USER + 69); private const int WM_SETREDRAW = 0x0b; private IntPtr OldEventMask; [DllImport(“user32.dll”, CharSet=CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); public void BeginUpdate() { SendMessage(this.Handle, WM_SETREDRAW, IntPtr.Zero, IntPtr.Zero); OldEventMask = (IntPtr)SendMessage(this.Handle, EM_SETEVENTMASK, … Read more