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#中的类型系统(值类型和引用类型)的简单介绍

C#是什么?有什么用?

关于C#中三个关键字params,ref,out的详细介绍

C#接口的实例详解

C#中for循环的实例分析

详解winform C#中子窗体关闭刷新父窗体的示例代码

C#使用oledb连接excel执行insert into语句出现“必须使用一个可更新的查询”的解决办法的示例代码

C#中如何取绝对值函数的方法详解

C#从枚举值获取对应文本的图文代码详解

C# 应用npoi获取excel中的图片,保存至本地的算法的图文代码实例详解

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




打赏

取消

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

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

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

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

评论

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