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

 

你可能感兴趣的:(WinForm)