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就可以把横向闪烁光标( _ )修改成竖向闪烁光标样式( | )
随机推荐
- IBM总架构师寇文东谈程序员的职业规划
有些年轻的程序员向我咨询,将来的路该怎么走?俗话说,条条大路通罗马.不同的路都能走向成功,到底选择哪条路,取决于自己的兴趣.可能有程序员会问:如果还没有找到自己的兴趣怎么办?我的建议是多尝试,努力做, ...
- Consistent Hashing原理与实现
原理介绍: consistent hashing原理介绍来自博客:http://blog.csdn.net/sparkliang/article/details/5279393, 多谢博主的分享 co ...
- Razor引擎总结
1.显示格式化小数:@(string.Format("{0:0.00}",ViewData["TradeAmount"].ToNullString()))
- jMeter之二
jMeter应用的最小子集有如下三个概念: 首先是线程组(Thread Group),线程组意味着定义一下多少个线程,多长时间建立起来(模拟增量按照一定频度上扬)以及循环多少次: 第二个是采样器(Sa ...
- URL参数加密解密
/// <summary> /// DES加密字符串 /// </summary> /// <param name=" ...
- Jquery效果代码--(二)
//jQuery 效果- 隐藏和显示.通过 jQuery,您可以使用 hide() 和 show() 方法来隐藏和显示 HTML 元素: //掩藏效果演示: $(document).ready(fun ...
- C#方法定义和调用-2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- IAR ARM、IAR STM8、IAR MSP430共用一个IDE
转自IAR ARM.IAR STM8.IAR MSP430共用一个IDE 试了安装好多个不同版本不同编译器的IAR,终于明白不同编译器的IAR共用IDE的条件,把几个不同编译器的IAR安装在一起,共用 ...
- PYTHON---FILE IO
import pickle shoplistfile = 'shoplist.data' shoplist = ['apple', 'mango', 'carrot'] f = open(shopli ...
- UVA 10034 Freckles 最小生成树
虽然是道普通的最小生成树题目,可还是中间出了不少问题,暴露的一个问题是不够细心,不够熟练.所以这篇博客就当记录一下bug吧. 代码一:kruskal #include<stdio.h> # ...