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


本文摘自PHP中文网,作者黄舟,侵删。

C# 带滚动条的Label控件,用鼠标选的时候还是有点闪烁:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

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#如何利用reportviewer来生成报表的示例代码分享(图)

详解C#常见应用函数的实例总结

C#将unicode编码转换为汉字字符串的代码分析

C#devexpress gridcontrol日期行的显示格式设置详解(图文)

C#教程】C# 枚举(enum)

详细介绍C#中out和ref的区别(图文)

C#如何防止sql注入?

利用unity脚本自定义分辨率实现相机截一张高清截图

C#因其保护级别而不可访问,只能处理公共类型的详细代码介绍

使用c#操作windowad之的windows用户组

更多相关阅读请进入《C#》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...