日期:2014-05-17  浏览次数:21300 次

怎样才能屏蔽掉RichTextBox的Ctrl+鼠标Wheel缩放功能?
用户控件代码段:
    public partial class RichTextBox : System.Windows.Forms.RichTextBox
    {
        public RichTextBox()
        {
            InitializeComponent();
        }

        protected override void OnMouseWheel(MouseEventArgs e)
        {
            if (!IsKeyCtrlDown)
                base.OnMouseWheel(e);//这句屏蔽不掉RichTextBox的Ctrl+鼠标Wheel缩放功能
        }

        static object objForLock = new object();

        [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "GetKeyboardState")]
        public static extern int GetKeyboardState(byte[] pbKeyState);

        bool IsKeyCtrlDown
        {
            get
            {
                bool blT = false;
                byte[] byteBuffer = new byte[256];
                if (GetKeyboardState(byteBuffer) > 0)
                    blT = byteBuffer[17] >= 128;
                return blT;
            }
        }

为什么?
RichTextBox 鼠标缩放 屏蔽