コード例 #1
0
        public override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            SkinnableControl ctl = controls.FirstOrDefault(c => c.Capture);

            if (ctl == null)
            {
                ctl = controls.FirstOrDefault(c => c.HitTest(e.Location));
            }

            if (ctl == null)
            {
                // Gestione click
                if (!this.suppressNextClick)
                {
                    var capture = this.Capture;
                    var hit     = this.IsInside(e.Location);

                    if (e.Button == MouseButtons.Left && capture && hit)
                    {
                        this.OnClick(new EventArgs());
                    }
                }
            }
            else
            {
                var capture = ctl.Capture;
                var hit     = ctl.HitTest(e.Location);

                // Gestione click
                if (e.Button == MouseButtons.Left && capture && hit && !this.suppressNextClick)
                {
                    ctl.OnClick(new EventArgs());
                }

                MouseEventArgs e2 = new MouseEventArgs(e.Button, e.Clicks, e.X - (int)Math.Round(ctl.Left, 0, MidpointRounding.ToEven), e.Y - (int)Math.Round(ctl.Top, 0, MidpointRounding.ToEven), e.Delta);
                ctl.OnMouseUp(e2);

                if (capture && !hit)
                {
                    // Il capturing è finito e ora ci ritroviamo su un controllo diverso... lanciamo
                    // gli eventi MouseLeave / MouseEnter
                    ctl.OnMouseLeave(new EventArgs());
                    SkinnableControl enterctl = controls.FirstOrDefault(c => c.HitTest(e.Location));
                    if (enterctl != null)
                    {
                        lastEnterControl = enterctl;
                        enterctl.OnMouseEnter(new EventArgs());
                    }
                }
            }

            this.suppressNextClick = false;
        }
コード例 #2
0
        public override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            //var someoneHit = false;

            SkinnableControl ctl = controls.FirstOrDefault(c => c.Capture);

            if (ctl == null)
            {
                ctl = controls.FirstOrDefault(c => c.HitTest(e.Location));
                if (ctl != null)
                {
                    if (lastEnterControl != ctl)
                    {
                        // Lanciamo mouseLeave / mouseEnter sul vecchio / nuovo controllo sopra il quale ci troviamo.
                        if (lastEnterControl != null)
                        {
                            lastEnterControl.OnMouseLeave(new EventArgs());
                        }
                        lastEnterControl = ctl;
                        ctl.OnMouseEnter(new EventArgs());
                    }

                    MouseEventArgs e2 = new MouseEventArgs(e.Button, e.Clicks, e.X - (int)Math.Round(ctl.Left, 0, MidpointRounding.ToEven), e.Y - (int)Math.Round(ctl.Top, 0, MidpointRounding.ToEven), e.Delta);
                    ctl.OnMouseMove(e2);
                }
                else
                {
                    // Non ci troviamo sopra a nessun controllo: se qualcuno dei nostri
                    // controlli aveva il mouseEnter, gli chiamiamo mouseLeave.
                    if (lastEnterControl != null)
                    {
                        lastEnterControl.OnMouseLeave(new EventArgs());
                        lastEnterControl = null;
                    }
                }
            }
            else
            {
                MouseEventArgs e2 = new MouseEventArgs(e.Button, e.Clicks, e.X - (int)Math.Round(ctl.Left, 0, MidpointRounding.ToEven), e.Y - (int)Math.Round(ctl.Top, 0, MidpointRounding.ToEven), e.Delta);
                ctl.OnMouseMove(e2);
            }
        }