C# 带滚动条的Label控件的示例代码详解

黄舟
发布: 2017-03-13 17:49:20
原创
3212 人浏览过

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;
            }
        }
    }
}
登录后复制

效果:



以上是C# 带滚动条的Label控件的示例代码详解的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!