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;

            }

        }

    }

}

效果:

阅读剩余部分

相关阅读 >>

详细介绍winformC#获得mac地址,ip地址,子网掩码,默认网关的代码实例(图)

C#异常增强

C# win32控制台应用程序忽略ctrl + c阻止程序退出的代码示例(图)

C#中如何实现两个richtextbox控件滚动条同步滚动的方法详解

C#灵活使用类的方法分享

C#高级编程(三)-对象和类型详解

C# winform webbrowser 设置为编辑模式的示例代码

详解C#接口在派生类和外部类中的调用方法示例

C#实现网络电子白板、课件功能 (在线教学系统)

C#中sealed关键字的作用详解

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




打赏

取消

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

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

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

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

评论

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