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中文网其它相关文章!
前端(VUE)零基础到就业课程:点击学习
自己动手写 PHP MVC 框架:点击学习
![](http://m.sbmmt.com/img/upload/article/000/000/020/633501a29d313483.png)