C# 带滚动条的Label控件

简介: C# 带滚动条的Label控件,用鼠标选的时候还是有点闪烁:namespace 带滚动条的Label控件{ public class TextBoxLabel : System.Windows.

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


目录
相关文章
|
5月前
|
C# 数据库 开发者
44.c#:combobox控件
44.c#:combobox控件
61 1
|
5月前
|
C# 数据库
40.c#:TreeView 控件
40.c#:TreeView 控件
57 1
|
2月前
|
C#
|
4月前
|
索引
详细解读c#ListBox控件
详细解读c#ListBox控件
25 0
|
5月前
|
SQL 存储 Oracle
C# Web控件与数据感应之 Control 类
C# Web控件与数据感应之 Control 类
|
5月前
|
SQL 存储 C#
C# Web控件与数据感应之 TreeView 类
C# Web控件与数据感应之 TreeView 类
|
5月前
|
SQL 存储 Oracle
C# Web控件与数据感应之 CheckBoxList 类
C# Web控件与数据感应之 CheckBoxList 类
|
5月前
|
SQL 存储 Oracle
C# Web控件与数据感应之 ListControl 类
C# Web控件与数据感应之 ListControl 类
|
5月前
|
JavaScript 前端开发 C#
C# webbrowser控件设置代理IP访问网站
C# webbrowser控件设置代理IP访问网站
331 5
|
5月前
|
C# Windows
49.c#:StatusStrip 控件
49.c#:StatusStrip 控件
104 1
49.c#:StatusStrip 控件