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#打印一个n行的菱形?实战详解

.net的优点

C#字符串处理小工具的详细介绍

C#中反射是什么?

C#中泛型委托的示例代码分享(图)

几个优秀的java和C#代码转换工具

C#相关面试题

C#实现在listview中插入图片的示例代码分享

C#实现windows剪贴板监视器的代码具体介绍

.net是否真的被国内市场嫌弃?

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




打赏

取消

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

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

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

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

评论

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