• 技术文章 >后端开发 >C#.Net教程

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

    黄舟黄舟2017-03-13 17:49:20原创2277
    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;
                }
            }
        }
    }

    效果:

    php入门到就业线上直播课:进入学习


    以上就是C# 带滚动条的Label控件的示例代码详解的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

    前端(VUE)零基础到就业课程:点击学习

    清晰的学习路线+老师随时辅导答疑

    自己动手写 PHP MVC 框架:点击学习

    快速了解MVC架构、了解框架底层运行原理

    上一篇:C# System.Drawing.Region类的方法使用(图解) 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • ❤️‍🔥共22门课程,总价3725元,会员免费学• ❤️‍🔥接口自动化测试不想写代码?• c语言中源文件编译后生成什么文件• c语言标识符有哪些类型• C#中GDI+编程10个基本技巧二• ASP.NET使用Ajax如何返回Json对象的方法具体介绍• 应用绝对路径与相对路径
    1/1

    PHP中文网