zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    hive 拉链表
    hive分组排序函数 分组取top10
    Hive metastore三种配置方式
    DB2基础学习3
    DB2基础学习2
    DB2的基础学习
    MySQL的基础学习
    虚拟机克隆,service network restart 重启失败
    两台电脑如何共享文件
    vmware下ubuntu14.04 nat方式上网
  • 原文地址:https://www.cnblogs.com/xe2011/p/3442914.html
Copyright © 2011-2022 走看看