RichtextBox去除闪烁光标
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去除闪烁光标的更多相关文章
- 模仿input闪烁光标
模仿闪烁的光标 <span class="cursor-blink"> </span> 样式代码: .cursor-blink { display: inl ...
- winform中RichTextBox在指定光标位置插入图片
代码如下: //获取RichTextBox控件中鼠标焦点的索引位置 int startPosition = this.richTextBox1.SelectionStart; //从鼠标焦点处开始选中 ...
- NotePad++中如何出去闪烁的光标?
当在写代码时出现的光标闪烁(横线闪烁),在键盘上找 Insert ,按这个Insert就可以把横向闪烁光标( _ )修改成竖向闪烁光标样式( | ),横向光标会在你写代码的时候修改前面的代码,把光标移 ...
- 在编程的时候,NotePad++ 中闪烁的光标突然有竖着闪烁的编程蓝色下划线闪烁的--小技巧告诉你-费元星
当在写代码时出现的光标闪烁(横线闪烁) 在键盘上找 Insert ,按这个Insert就可以把横向闪烁光标( _ )修改成竖向闪烁光标样式( | ),横向光标会在你写代码的时候修改前面的代码,把光标移 ...
- 将richTextBox中的内容写入txt文件发现不换行(解决方法),在richTextBox指定位置插入文字
string pathname = dt.ToString().Replace(":", ""); string str = richTextBoxResult ...
- CSS改变插入光标颜色caret-color简介及其它变色方法(转)
一.CSS改变输入框光标颜色的原生属性caret-color CSS caret-color属性可以改变输入框插入光标的颜色,同时又不改变输入框里面的内容的颜色. 例如: input { color: ...
- jQuery闪烁提示,让新消息在网页标题显示
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head& ...
- input光标使用caret-color改变颜色
本文转载自:https://www.zhangxinxu.com/wordpress/2018/01/css-caret-color-first-line/ CSS caret-color属性可以改变 ...
- NotePad++中如何改变光标样式(转换横着和竖着)?
在键盘上找 Insert ,按这个Insert就可以把横向闪烁光标( _ )修改成竖向闪烁光标样式( | )
随机推荐
- Java多线程初学者指南(5):join方法的使用
在上面的例子中多次使用到了Thread类的join方法.我想大家可能已经猜出来join方法的功能是什么了.对,join方法的功能就是使异步执行的线程变成同步执行.也就是说,当调用线程实例的start方 ...
- Swifter初体验;按照惯例,来一个Swift版本的:iOS图片验证码?
不多解释,上图,上代码:代码
- 更改JENKINS主目录
在部署时,发现直接启动WAR包没办法改主目录,而此主目录空间太小, 唯有安装TOMCAT之后进行更改... 参考文档: 工作中,由于Jenkins默认的主目录空间太小,导致需要将Jenkins默认的主 ...
- Oracle的常见错误及解决办法
ORA-12528: TNS:listener: all appropriate instances are blocking new connections ORA-12528问题是因为监听中的服务 ...
- http实现发送post请求,获取结果集
package com.ming; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.Ou ...
- 转:三十一、Java图形化界面设计——布局管理器之GridLayout(网格布局)
http://blog.csdn.net/liujun13579/article/details/7772491 网格布局特点: l 使容器中的各组件呈M行×N列的网格状分布. l 网格每列宽度相 ...
- 【Node】package.json
npm的package.json中文文档https://github.com/ericdum/mujiang.info/issues/6
- org.hibernate.LazyInitializationException: failed to lazily initialize
今天搞了一上午,都在解决这个问题:org.hibernate.LazyInitializationException: failed to lazily initialize 原因很简单,是在非法的s ...
- oracle 绑定变量
“绑定变量”这个词也许对于某些人来说看以来陌生,其实我们在很早的时候就已经开始运用它了. 在java中使用的PrepareStatement对象,大家一定会说这不是将sql语句做预编译操作嘛,被封装的 ...
- (转载)SQL联合查询中的关键语法
(转载)http://www.cnblogs.com/zhangliyu/archive/2009/03/21/1418215.html 联合查询效率较高.以下例子来说明联合查询的好处 t1表结构(用 ...