https://files.cnblogs.com/xe2011/CustomRichTextBox_HideCaret.rar
richTextBox能高亮选择,光标仍在,没有光标闪烁
把重RichTextBox类
去除闪烁光标 http://msdn.microsoft.com/en-us/library/windows/desktop/ms648403%28v=vs.85%29.aspx
using System; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsFormsApplication1 { public class CustomRichTextBox: RichTextBox { [DllImport("user32.dll")] static extern bool HideCaret(IntPtr hWnd);
protected override void WndProc(ref Message m) { base.WndProc(ref m); HideCaret(Handle); } } }
完整代码
CustomRichTextBox.CS
using System; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsFormsApplication1 { public class CustomRichTextBox : RichTextBox { [DllImport("user32.dll")] static extern bool HideCaret(IntPtr hWnd); private bool bReadOnly = false; public void SetReadMode() { ReadOnly = true; bReadOnly = true; } public void SetEditMode() { ReadOnly = false; bReadOnly = false; Focus(); } protected override void WndProc(ref Message m) { base.WndProc(ref m); if (bReadOnly) HideCaret(Handle); } } }