淺析如何屏蔽C#鼠標(biāo)滾輪相關(guān)事件
作者:佚名
這里將介紹如何屏蔽C#鼠標(biāo)滾輪相關(guān)事件,本代碼示例主要解決滾動鼠標(biāo)滾動就改變值的問題。希望本文能對大家有所幫助。
C#鼠標(biāo)滾輪主要是針對鼠標(biāo)上的滾輪滾動中,改變值的問題。通過這一代碼能解決這個問題,其中需要用到IMessageFilter 成員。C#鼠標(biāo)滾輪也是鼠標(biāo)控制的重要組成部分。
- 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 );
- }
- }
- 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 );
- }
- }
這樣就可以實現(xiàn)當(dāng)一個控件,比如commbox或者numupdown等獲得焦點的時候,滾動鼠標(biāo)滾動就不會改變值了。
如何屏蔽C#鼠標(biāo)滾輪相關(guān)事件就介紹到這里。
【編輯推薦】
責(zé)任編輯:彭凡
來源:
e800技術(shù)客