博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# 带滚动栏的Label控件
阅读量:7046 次
发布时间:2019-06-28

本文共 1279 字,大约阅读时间需要 4 分钟。

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

你可能感兴趣的文章
MySQL高级-索引优化
查看>>
SQL中Group By的使用
查看>>
RateLimiter 限流
查看>>
资深设计师Tony Ventrice解析手机游戏开发的四个层次
查看>>
Swift入门篇-结构体
查看>>
Using the Eclipse Jobs-API(转载)
查看>>
GCC编译过程
查看>>
AE intersect、clip的实现
查看>>
图解使用Win8Api进行Metro风格的程序开发一----建立我们的导航架构
查看>>
iOS开发过程中使用Core Data应避免的十个错误
查看>>
I.MX6 wpa_cli 使用
查看>>
windows使用nginx实现网站负载均衡测试实例
查看>>
DotLiquid模板引擎简介
查看>>
5.Flask-Migrate
查看>>
c# 正则表代式的分组和批评模式 .
查看>>
编程之美-3.1-字符串移位包含的问题
查看>>
EPC是什么
查看>>
T-SQL查询进阶--数据集之间的运算
查看>>
【Vegas原创】Linux下unrar安装与配置
查看>>
HDOJ 2095(找出唯一的出现一次的数)
查看>>