ComboBox控件有时当焦点离开自身时,也会响应鼠标的滚轮事件。在有些时候会影响用户体验,可以在必要的时候将其禁用掉。本文收集了一些解决方法:
方法一:
public partial class Form1 : Form, IMessageFilter { public Form1() { InitializeComponent(); } #region IMessageFilter 成员 public bool PreFilterMessage(ref Message m) { if (m.Msg == 522) { return true; } else { return false; } } #endregion private void Form1_Load(object sender, EventArgs e) { Application.AddMessageFilter(this); } }
方法二:
class comBoBoxEx : System.Windows.Forms.ComboBox { public bool isWheel = false; public string strComB = null; protected override void OnMouseWheel(System.Windows.Forms.MouseEventArgs e) { strComB = Text; isWheel = true; } protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) { base.OnMouseDown(e); isWheel = false; } protected override void OnTextChanged(EventArgs e) { base.OnTextChanged(e); if (isWheel) { Text = strComB; } } }
已有 13157 位网友参与,快来吐槽:
发表评论