• 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);
            }
        }  
    }
    View Code

    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();
            }
        }
    }
    View Code

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

    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);
            }
        }   
    }
    View Code

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

  • 相关阅读:
    [Codeforces Round #516][Codeforces 1063C/1064E. Dwarves, Hats and Extrasensory Abilities]
    接入gitment为hexo添加评论功能
    常用SQL语句
    小米前端二面面经
    将hexo的评论系统由gitment改为Valine
    同步与异步
    前端构建工具对比
    前端向后台发送请求有哪些方式
    关于hexo markdown添加的图片在github page中无法显示的问题
    使用TensorBoard可视化工具
  • 原文地址:https://www.cnblogs.com/xe2011/p/3442914.html
Copyright © 2020-2023  润新知