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#中dataset的用法

详细介绍C#实例化接口对象的方法

C#中for循环的实例分析

C#实现检索不区分大小写并高亮显示的示例代码分享

使用C#生成pdf文件流的代码案例分享

C# 日志记录类创建的源码分享

dictionary字典类在C#中的示例代码介绍

详细介绍C# 利用irawpixels接口遍历栅格数据的代码实例

简单介绍C#类的继承的示例代码

.net框架-微软给出的C#编程风格代码实例

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




打赏

取消

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

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

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

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

评论

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