我是靠谱客的博主 细心月亮,这篇文章主要介绍禁用鼠标滚轮事件(对单个下拉控件,不影响其他控件的滚轮事件),现在分享给大家,希望可以做个参考。

public partial class ComEdit:Combobox,IMessageFilter
{
        public ComEdit()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            
            Application.AddMessageFilter(this);
            this.MouseEnter += ComEdit_MouseEnter;
            this.MouseLeave += ComEdit_MouseLeave;
        }


        #region 禁用鼠标滚轮事件
        ///
        /// 判断鼠标是否在控件上
        ///
        bool IsFoused { get; set; } = false;
        private void ComEdit_MouseLeave(object sender, EventArgs e)
        {
            IsFoused = false;
        }

        private void ComEdit_MouseEnter(object sender, EventArgs e)
        {
            IsFoused = true;
        }

        public bool PreFilterMessage(ref Message m)
        {
            if (IsFoused)
            {
                if (m.Msg == 0x020A)
                    return true;
                return false;
            }
            return false;
        }
        #endregion
}

最后

以上就是细心月亮最近收集整理的关于禁用鼠标滚轮事件(对单个下拉控件,不影响其他控件的滚轮事件)的全部内容,更多相关禁用鼠标滚轮事件(对单个下拉控件,不影响其他控件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(44)

评论列表共有 0 条评论

立即
投稿
返回
顶部