http://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);
}
}
}

Form1.CS

using System;
using System.Collections.Generic; using System.Text;
using System.Windows.Forms; namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click_1(object sender, EventArgs e)
{
CustomRichTextBox1.SetReadMode();
} private void button2_Click(object sender, EventArgs e)
{
CustomRichTextBox1.SetEditMode();
}
}
}

这种写法更彻底,不能选择

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices; namespace WindowsFormsApplication1
{ public class CustomRichTextBox : RichTextBox
{
private const int WM_SETFOCUS = 0x7;
private const int WM_LBUTTONDOWN = 0x201;
private const int WM_LBUTTONUP = 0x202;
private const int WM_LBUTTONDBLCLK = 0x203;
private const int WM_RBUTTONDOWN = 0x204;
private const int WM_RBUTTONUP = 0x205;
private const int WM_RBUTTONDBLCLK = 0x206;
private const int WM_KEYDOWN = 0x0100;
private const int WM_KEYUP = 0x0101; protected override void WndProc(ref Message m)
{
if (m.Msg == WM_SETFOCUS || m.Msg == WM_KEYDOWN || m.Msg == WM_KEYUP || m.Msg == WM_LBUTTONDOWN || m.Msg == WM_LBUTTONUP || m.Msg == WM_LBUTTONDBLCLK || m.Msg == WM_RBUTTONDOWN || m.Msg == WM_RBUTTONUP || m.Msg == WM_RBUTTONDBLCLK)
{
return;
}
base.WndProc(ref m);
}
}
}

附件 http://files.cnblogs.com/xe2011/CustomRichTextBox1ReadMode.rar

RichtextBox去除闪烁光标的更多相关文章

  1. 模仿input闪烁光标

    模仿闪烁的光标 <span class="cursor-blink"> </span> 样式代码: .cursor-blink { display: inl ...

  2. winform中RichTextBox在指定光标位置插入图片

    代码如下: //获取RichTextBox控件中鼠标焦点的索引位置 int startPosition = this.richTextBox1.SelectionStart; //从鼠标焦点处开始选中 ...

  3. NotePad++中如何出去闪烁的光标?

    当在写代码时出现的光标闪烁(横线闪烁),在键盘上找 Insert ,按这个Insert就可以把横向闪烁光标( _ )修改成竖向闪烁光标样式( | ),横向光标会在你写代码的时候修改前面的代码,把光标移 ...

  4. 在编程的时候,NotePad++ 中闪烁的光标突然有竖着闪烁的编程蓝色下划线闪烁的--小技巧告诉你-费元星

    当在写代码时出现的光标闪烁(横线闪烁) 在键盘上找 Insert ,按这个Insert就可以把横向闪烁光标( _ )修改成竖向闪烁光标样式( | ),横向光标会在你写代码的时候修改前面的代码,把光标移 ...

  5. 将richTextBox中的内容写入txt文件发现不换行(解决方法),在richTextBox指定位置插入文字

    string pathname = dt.ToString().Replace(":", ""); string str = richTextBoxResult ...

  6. CSS改变插入光标颜色caret-color简介及其它变色方法(转)

    一.CSS改变输入框光标颜色的原生属性caret-color CSS caret-color属性可以改变输入框插入光标的颜色,同时又不改变输入框里面的内容的颜色. 例如: input { color: ...

  7. jQuery闪烁提示,让新消息在网页标题显示

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head& ...

  8. input光标使用caret-color改变颜色

    本文转载自:https://www.zhangxinxu.com/wordpress/2018/01/css-caret-color-first-line/ CSS caret-color属性可以改变 ...

  9. NotePad++中如何改变光标样式(转换横着和竖着)?

    在键盘上找 Insert ,按这个Insert就可以把横向闪烁光标( _ )修改成竖向闪烁光标样式( | )

随机推荐

  1. “typedef int (init_fnc_t) (void);“的含义

    在读uboot的lib_arm/board.c中的start_armboot ()函数遇到了"init_fnc_t **init_fnc_ptr;”一句话,后来查看init_fnt_t数据类 ...

  2. share my tools With Xcode

    1.让Xcode的控制台支持LLDB类型的打印 在Xcode断点调试的时候, 在控制台输入 po self.view.frame 或者 po id 类型的时候就死翘翘了. 进入正题: 安装LLDB调试 ...

  3. 关于textjs的tree带复选框的树

    通过查阅一些资料和自己之前了解到的一些相关知识,有时项目中需要用到.话不多说,先看一下效果图: 我写的这人员选择的树,主要是改写了TreePanel,如下代码: ExtendTreePanel.js ...

  4. ms-on-input

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  5. 转:浅谈命令查询职责分离(CQRS)模式

    原文来自于:http://www.cnblogs.com/yangecnu/p/Introduction-CQRS.html 在常用的三层架构中,通常都是通过数据访问层来修改或者查询数据,一般修改和查 ...

  6. complex(x):创建一个复数

    使用python可以实现将一个整数或者浮点数转换为一个复数: 演示如下: >>> # 演示复数函数:complex(x) ... >>> x = complex(1 ...

  7. ubuntu service

    http://blog.chinaunix.net/uid-21528208-id-2399656.html

  8. linux svn服务器搭建、客户端操作、备份与恢复

    Subversion(SVN)是一个开源的版本控制系統,管理着随时间改变的数据.这些数据放置在一个中央资料档案库中,这个档案库很像一个普通的文件服务器,它会记住每一次文件的变动,这样就可以把档案恢复到 ...

  9. NOI2005瑰丽华尔兹

    1499: [NOI2005]瑰丽华尔兹 Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 893  Solved: 508[Submit][Status] ...

  10. SQL Server 2005 To Oracle

    近期因为项目需要,将SQLServer2005转成Oracle 在这里介绍下转换步骤: 1. 准备好你要转换的数据,如图 2. 右键单击 任务/导出数据,如图 3. 执行完之后就打开选择数据源页面,填 ...