C # differs from the mouse scrolling programming of WIN10 and non-Win10 windows systems.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.