C#(Winform)禁用TextBox控件的鼠标事件

1. 继承TextBox,然后重写父类的部分方法,核心代码如下 

public class MyTextBox : TextBox
    {
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case 0x0201://WM_LBUTTONDOWN
                    {
                        return;
                    }
                case 0x0202://WM_LBUTTONUP
                    {
                        return;
                    }
                case 0x0203://WM_LBUTTONDBLCLK
                    {
                        return;
                    }
                case 0x0204://WM_RBUTTONDOWN
                    {
                        return;
                    }
                case 0x0205://WM_RBUTTONUP
                    {
                        return;
                    }
                case 0x0206://WM_RBUTTONDBLCLK
                    {
                        return;
                    }
            }

            base.WndProc(ref m);
        }
    }
View Code

 

posted @ 2015-04-21 17:58  一菲聪天  阅读(3627)  评论(0编辑  收藏  举报