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就可以把横向闪烁光标( _ )修改成竖向闪烁光标样式( | )
随机推荐
- vs15
vs15 preview5 离线安装包 vs15 preview5 离线安装包 1.介绍 vs15是微软打造的新一代IDE,全新的安装方式.官网介绍如下(https://blogs.msdn.mi ...
- RegexKitLite 使用详解
1.去RegexKitLite下载类库,解压出来会有一个例子包及2个文件,其实用到的就这2个文件,添加到工程中. 2.工程中添加libicucore.dylib frameworks. 友情提醒:一般 ...
- QT窗口渐现效果,窗口震动效果,鼠标移动窗口
//窗口渐现效果void MainWindow::closeWindowAnimation() //关闭窗口效果 { QPropertyAnimation *animation = new QProp ...
- C语言可变参数在宏定义中的应用
在C语言的标准库中,printf.scanf.sscanf.sprintf.sscanf这些标准库的输入输出函数,参数都是可变的.在调试程序时,我们可能希望定义一个参数可变的输出函数来记录日志,那么用 ...
- AFN演示
- leetcode面试准备:Divide Two Integers
leetcode面试准备:Divide Two Integers 1 题目 Divide two integers without using multiplication, division and ...
- WCF的配置文件中的要素
Windows Communication Foundation Configuration Schema
- 详解Makefile 函数的语法与使用
使用函数: 在Makefile中可以使用函数来处理变量,从而让我们的命令或是规则更为的灵活和具有智能.make所支持的函数也不算很多,不过已经足够我们的操作了.函数调用后,函数的返回值可以当做变量来使 ...
- 作品第一课----获取批量checkbox选中的值
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- HDOJ/HDU Tempter of the Bone(深搜+奇偶性剪枝)
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...