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

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控件的示例代码详解

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2549621.html

(0)
上一篇 2025年3月6日 05:45:32
下一篇 2025年3月6日 05:45:40

AD推荐 黄金广告位招租... 更多推荐

发表回复

登录后才能评论