C # handles mouse scrolling on win10 and non-Win10 with some differences, building a Form1, placing a FlowLayoutPanel, type Panel1
Panel.mousewheel + = panelonmousewheel; Private void Panelonmousewheel (object sender, MouseEventArgs MouseEventArgs) { if0) = Scrollbar.value = = Scrollbar.maximum? Scrollbar.maximum: + +scrollbar.value ; Else = Scrollbar.value = = Scrollbar.minimum? Scrollbar.minimum:--scrollbar.value; }
The above code on the Win10, as long as the mouse in the Panel1 client area, then scrolling the mouse wheel, you can trigger the scrolling event, but on the non-WIN10, if the focus is not on the panel, such as in the Form1 form a button, then cannot trigger the scrolling event.
Solutions
[DllImport ("user32.dll")] Public Static extern IntPtr GetFocus ();
You need to determine if the focus button is the child control of this window, using IMessageFilter.
Const intWM_MouseWheel =0x020a; Public BOOLPrefiltermessage (refMessage msg) { if(Msg. MSG = =WM_MouseWheel) { if((Checkcontrol ( This. Parent, GetFocus () ))) {intWpara = (int) Msg. WParam; if((Wpara &0x80000000) ==0x80000000)//downwardScrollbar.value = Scrollbar.value = = Scrollbar.maximum? Scrollbar.maximum: + +Scrollbar.value; ElseScrollbar.value= Scrollbar.value = = Scrollbar.minimum? Scrollbar.minimum:--Scrollbar.value; } return false; } return false; }
Public BOOLCheckcontrol (Control control, INTPTR handle) {if(Control = =NULL) return false; Try { for(inti =0; I < control. Controls.Count; i++) { varv =control. Controls[i]; if(Handle = =v.handle) { return true; } Else { if(V.controls.count >0) { if(Checkcontrol (v, handle)) {return true; } } } } } Catch(Exception e) {Console.WriteLine (e); return false; } return false; }
If there is a better solution, please advise.
C # differs from the mouse scrolling programming of WIN10 and non-Win10 windows systems.