using System; using System.Drawing; using System.ComponentModel; using System.Windows.Forms; namespace ListViewEmbeddedControls { /// <summary> /// Zusammenfassung f�r ReadOnlyRichTextBox. /// </summary> public class ReadOnlyRichTextBox : RichTextBox { public ReadOnlyRichTextBox() { ReadOnly=true; TabStop=false; SetStyle(ControlStyles.Selectable, false); } // Font is overridden because assigning the RichTextBox to a new parent sets // its Font to the parent's Font and thus loses all formatting of existing RTF content. protected Font _font = new Font("Arial", 10); public override Font Font { get { return _font; } set { _font = value; } } [ Browsable(false) ] public new bool ReadOnly { get { return true; } set { } } [ Browsable(false) ] public new bool TabStop { get { return false; } set { } } const int WM_SETFOCUS = 0x0007; protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_SETFOCUS: // We don't want the RichTextBox to be able to receive focus, so just // pass the focus back to the control it came from. IntPtr prevCtl = m.WParam; Control c = Control.FromHandle(prevCtl); c.Select(); return; } base.WndProc (ref m); } } }
By viewing downloads associated with this article you agree to the Terms of use and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Math Primers for Programmers