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. 安装app到Simulator

    1.安装brew 打开命令行,执行以下命令: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install ...

  2. c++ 函数的函数声明

    c++ 函数的函数声明 只要在被调用函数的首部的末尾加一个分号,就成为对该函数的函数声明.函数声明的位置应当在函数调用之前. #include <iostream> using names ...

  3. BZOJ 1571: [Usaco2009 Open]滑雪课Ski

    Description Farmer John 想要带着 Bessie 一起在科罗拉多州一起滑雪.很不幸,Bessie滑雪技术并不精湛. Bessie了解到,在滑雪场里,每天会提供S(0<=S& ...

  4. Druid :大数据实时处理的开源分布式系统(1)

    引言 Druid 是一个快速,近实时的查询海量只读数据的系统.Druid 的目标是可用性要达到100%,即使在部署新代码,或者某些节点 down 机的情况下. Druid 目前支持的单表查询方式和 D ...

  5. JavaScript 作用域和变量提升

    本文是这篇文章的简单翻译. 如果按照下面的代码按照JavaScript程序的执行方式执行,alert函数会显示什么? var foo = 1; function bar() { if (!foo) { ...

  6. ASP.NET MVC 解决LINQ表达式中的SqlMethods 未找到命名空间问题

    右键项目属性下的引用: 添加引用: 搜索寻找——System.Data.Linq,然后添加成功,即可解决LINQ表达式中的SqlMethods 未找到命名空间问题

  7. linux下阅读源代码的工具

    说来真是惭愧呀.一直在用VIM 做开发.却不知道VI 里还有这么好使的工具.以前一直都是用: find -type f -print | xargs grep -i **** 在源代码里查找. 原来L ...

  8. java.lang.Comparable接口

    转自:http://blog.csdn.net/zccst/article/details/5092920 java.lang.Comparable 接口 作者: zccst java.lang.Co ...

  9. Devexpress之DateEdit学习,可选择日期时 zt

    DateEdit默认是是值只可以选择日期的,下面就来看看怎么设置可以选择时间. 代码如下. 设置以下属性 dateEdit1.Properties.VistaDisplayMode = DevExpr ...

  10. HDU-1495 非常可乐(BFS)

    广搜的灵活应用题: 非常可乐 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...