zoukankan      html  css  js  c++  java
  • C# 带滚动栏的Label控件

    C# 带滚动栏的Label控件,用鼠标选的时候还是有点闪烁:

    namespace 带滚动栏的Label控件
    {
        public class TextBoxLabel : System.Windows.Forms.TextBox
        {
            [DllImport("user32", EntryPoint = "HideCaret")]
            private static extern bool HideCaret(IntPtr hWnd);
    
            [DllImport("user32", EntryPoint = "ShowCaret")]
            private static extern bool ShowCaret(IntPtr hWnd);
    
            public TextBoxLabel():base(){
    
                this.TabStop = false;
                this.SetStyle(ControlStyles.Selectable, false);
                this.Cursor = Cursors.Default;
                this.ReadOnly = true;
                this.ShortcutsEnabled = false;
                this.HideSelection = true;
                this.GotFocus += new EventHandler(TextBoxLabel_GotFocus);
                this.MouseMove += new MouseEventHandler(TextBoxLabel_MouseMove);
            }
    
            private void TextBoxLabel_GotFocus(Object sender, System.EventArgs e){
                if (ShowCaret(((TextBox)sender).Handle)){
                    HideCaret(((TextBox)sender).Handle);
                }
            }
    
            private void TextBoxLabel_MouseMove(Object sender, MouseEventArgs e){
                if (((TextBox)sender).SelectedText.Length > 0){
                    ((TextBox)sender).SelectionLength = 0;
                }
            }
        }
    }

    效果:



    实现思路及用途參考:http://bbs.csdn.net/topics/390632325?page=1#post-398542672


  • 相关阅读:
    迷宫最短路问题
    回溯算法
    解题报告:poj1321 棋盘问题
    矩阵、分数、点、线类
    判断图像中有多少行文本(开发中)
    图形-回行扫描函数
    贝叶斯分类器
    js解析数学运算公式
    用postcss给less加上webkit前缀
    node创建文件夹
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4314092.html
Copyright © 2011-2022 走看看