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