private void EditingControls_CommonMouseEventHandler(object sender, MouseEventArgs e, DataGridViewMouseEvent dgvme)
        {
            Debug.Assert(this.ptCurrentCell.X != -1);
            int adjustedX = this.editingPanel.Location.X + e.X; 
            int adjustedY = this.editingPanel.Location.Y + e.Y;
            if (sender == this.editingControl)
            {
                adjustedX += this.editingControl.Location.X;
                adjustedY += this.editingControl.Location.Y;
            }

            if (dgvme == DataGridViewMouseEvent.MouseDown && e.Clicks == 1)
            {
                // Reset the flag that records single-click exposed as double-click.
                this.dataGridViewOper[DATAGRIDVIEWOPER_lastEditCtrlClickDoubled] = false;
            }

            MouseEventArgs me = new MouseEventArgs(e.Button, 
                                                   e.Clicks, 
                                                   adjustedX, 
                                                   adjustedY, 
                                                   e.Delta);

            HitTestInfo hti = HitTest(me.X, me.Y);
            int mouseX = me.X - hti.ColumnX;
            if (this.RightToLeftInternal)
            {
                mouseX += ((hti.col == -1) ? this.RowHeadersWidth : this.Columns[hti.col].Thickness);
            }
            DataGridViewCellMouseEventArgs dgvcme = new DataGridViewCellMouseEventArgs(hti.col, hti.row, mouseX, me.Y - hti.RowY, me);

            try
            {
                this.dataGridViewState2[DATAGRIDVIEWSTATE2_messageFromEditingCtrls] = true;
                // Check to see if this is a CellMouseDoubleClick situation
                if ((dgvme == DataGridViewMouseEvent.MouseDown || 
                     dgvme == DataGridViewMouseEvent.Click || 
                     dgvme == DataGridViewMouseEvent.MouseClick) &&
                    (DateTime.Now.Ticks - this.lastMouseClickInfo.timeStamp) / 10000 <= SystemInformation.DoubleClickTime &&
                    e.Button == this.lastMouseClickInfo.button &&
                    e.Clicks == 1 &&
                    dgvcme.ColumnIndex == this.lastMouseClickInfo.col &&
                    dgvcme.RowIndex == this.lastMouseClickInfo.row)
                {
                    Size hotDoubleClickZone = SystemInformation.DoubleClickSize;
                    if (Math.Abs(dgvcme.X - this.lastMouseClickInfo.x) <= hotDoubleClickZone.Width / 2 &&
                        Math.Abs(dgvcme.Y - this.lastMouseClickInfo.y) <= hotDoubleClickZone.Height / 2)
                    {
                        me = new MouseEventArgs(e.Button,
                                                2,
                                                adjustedX,
                                                adjustedY,
                                                e.Delta);
                        dgvcme = new DataGridViewCellMouseEventArgs(dgvcme.ColumnIndex, dgvcme.RowIndex, dgvcme.X, dgvcme.Y, me);
                        switch (dgvme)
                        {
                            case DataGridViewMouseEvent.MouseDown:
                            {
                                OnMouseDown(me);
                                if (dgvcme.ColumnIndex < this.Columns.Count &&
                                    dgvcme.RowIndex < this.Rows.Count)
                                {
                                    OnCellMouseDown(dgvcme);
                                }
                                break;
                            }
                            case DataGridViewMouseEvent.Click:
                            {
                                OnDoubleClick(me);
                                if (e.Button == MouseButtons.Left && 
                                    dgvcme.ColumnIndex < this.Columns.Count &&
                                    dgvcme.RowIndex < this.Rows.Count)
                                {
                                    OnCellDoubleClick(new DataGridViewCellEventArgs(dgvcme.ColumnIndex, dgvcme.RowIndex));
                                }
                                break;
                            }
                            case DataGridViewMouseEvent.MouseClick:
                            {
                                // Set the flag that prevents the triple-click to be exposed as a double-click
                                this.dataGridViewOper[DATAGRIDVIEWOPER_lastEditCtrlClickDoubled] = true;

                                OnMouseDoubleClick(me);
                                if (dgvcme.ColumnIndex < this.Columns.Count && dgvcme.RowIndex < this.Rows.Count)
                                {
                                    OnCellMouseDoubleClick(dgvcme);
                                }
                                break;
                            }
                        }
                        return;
                    }
                }

                if (this.dataGridViewOper[DATAGRIDVIEWOPER_lastEditCtrlClickDoubled])
                {
                    // Make sure that the triple-click is exposed as a single-click and not a double-click.
                    if (e.Clicks == 2)
                    {
                        me = new MouseEventArgs(e.Button,
                                                1,
                                                adjustedX,
                                                adjustedY,
                                                e.Delta);
                        dgvcme = new DataGridViewCellMouseEventArgs(hti.col, hti.row, mouseX, me.Y - hti.RowY, me);
                    }
                    switch (dgvme)
                    {
                        case DataGridViewMouseEvent.DoubleClick:
                            dgvme = DataGridViewMouseEvent.Click;
                            break;
                        case DataGridViewMouseEvent.MouseDoubleClick:
                            dgvme = DataGridViewMouseEvent.MouseClick;
                            break;
                    }
                }

                switch (dgvme)
                {
                    case DataGridViewMouseEvent.Click:
                        OnClick(me);
                        if (e.Button == MouseButtons.Left &&
                            dgvcme.ColumnIndex < this.Columns.Count &&
                            dgvcme.RowIndex < this.Rows.Count)
                        {
                            OnCellClick(new DataGridViewCellEventArgs(dgvcme.ColumnIndex, dgvcme.RowIndex));
                        }
                        break;
                    case DataGridViewMouseEvent.DoubleClick:
                        OnDoubleClick(me);
                        if (e.Button == MouseButtons.Left &&
                            dgvcme.ColumnIndex < this.Columns.Count &&
                            dgvcme.RowIndex < this.Rows.Count)
                        {
                            OnCellDoubleClick(new DataGridViewCellEventArgs(dgvcme.ColumnIndex, dgvcme.RowIndex));
                        }
                        break;
                    case DataGridViewMouseEvent.MouseClick:
                        OnMouseClick(me);
                        if (dgvcme.ColumnIndex < this.Columns.Count &&
                            dgvcme.RowIndex < this.Rows.Count)
                        {
                            OnCellMouseClick(dgvcme);
                        }
                        break;
                    case DataGridViewMouseEvent.MouseDoubleClick:
                        OnMouseDoubleClick(me);
                        if (dgvcme.ColumnIndex < this.Columns.Count &&
                            dgvcme.RowIndex < this.Rows.Count)
                        {
                            OnCellMouseDoubleClick(dgvcme);
                        }
                        break;
                    case DataGridViewMouseEvent.MouseDown:
                        OnMouseDown(me);
                        if (dgvcme.ColumnIndex < this.Columns.Count &&
                            dgvcme.RowIndex < this.Rows.Count)
                        {
                            OnCellMouseDown(dgvcme);
                        }
                        break;
                    case DataGridViewMouseEvent.MouseUp:
                        if (this.dataGridViewState2[DATAGRIDVIEWSTATE2_nextMouseUpIsDouble])
                        {
                            MouseEventArgs meTmp = new MouseEventArgs(e.Button,
                                                                      2,
                                                                      adjustedX,
                                                                      adjustedY,
                                                                      e.Delta);
                            dgvcme = new DataGridViewCellMouseEventArgs(dgvcme.ColumnIndex, dgvcme.RowIndex, dgvcme.X, dgvcme.Y, meTmp);
                        }
                        OnCellMouseUp(dgvcme);
                        OnMouseUp(me);
                        break;
                    case DataGridViewMouseEvent.MouseMove:
                        OnCellMouseMove(dgvcme);
                        break;
                }
            }
            finally
            {
                this.dataGridViewState2[DATAGRIDVIEWSTATE2_messageFromEditingCtrls] = false;
            }
        }
        private void EditingControls_CommonMouseEventHandler(object sender, MouseEventArgs e, DataGridViewMouseEvent dgvme)
        {
            int x = this.editingPanel.Location.X + e.X;
            int y = this.editingPanel.Location.Y + e.Y;
            if (sender == this.editingControl)
            {
                x += this.editingControl.Location.X;
                y += this.editingControl.Location.Y;
            }
            if ((dgvme == DataGridViewMouseEvent.MouseDown) && (e.Clicks == 1))
            {
                this.dataGridViewOper[0x1000] = false;
            }
            MouseEventArgs args = new MouseEventArgs(e.Button, e.Clicks, x, y, e.Delta);
            HitTestInfo info = this.HitTest(args.X, args.Y);
            int localX = args.X - info.ColumnX;
            if (this.RightToLeftInternal)
            {
                localX += (info.col == -1) ? this.RowHeadersWidth : this.Columns[info.col].Thickness;
            }
            DataGridViewCellMouseEventArgs args2 = new DataGridViewCellMouseEventArgs(info.col, info.row, localX, args.Y - info.RowY, args);
            try
            {
                this.dataGridViewState2[0x8000000] = true;
                if ((((dgvme == DataGridViewMouseEvent.MouseDown) || (dgvme == DataGridViewMouseEvent.Click)) || (dgvme == DataGridViewMouseEvent.MouseClick)) && ((((((DateTime.Now.Ticks - this.lastMouseClickInfo.timeStamp) / 0x2710L) <= SystemInformation.DoubleClickTime) && (e.Button == this.lastMouseClickInfo.button)) && ((e.Clicks == 1) && (args2.ColumnIndex == this.lastMouseClickInfo.col))) && (args2.RowIndex == this.lastMouseClickInfo.row)))
                {
                    Size doubleClickSize = SystemInformation.DoubleClickSize;
                    if ((Math.Abs((int) (args2.X - this.lastMouseClickInfo.x)) <= (doubleClickSize.Width / 2)) && (Math.Abs((int) (args2.Y - this.lastMouseClickInfo.y)) <= (doubleClickSize.Height / 2)))
                    {
                        args = new MouseEventArgs(e.Button, 2, x, y, e.Delta);
                        args2 = new DataGridViewCellMouseEventArgs(args2.ColumnIndex, args2.RowIndex, args2.X, args2.Y, args);
                        switch (dgvme)
                        {
                            case DataGridViewMouseEvent.Click:
                                this.OnDoubleClick(args);
                                if (((e.Button == MouseButtons.Left) && (args2.ColumnIndex < this.Columns.Count)) && (args2.RowIndex < this.Rows.Count))
                                {
                                    this.OnCellDoubleClick(new DataGridViewCellEventArgs(args2.ColumnIndex, args2.RowIndex));
                                }
                                break;

                            case DataGridViewMouseEvent.MouseClick:
                                this.dataGridViewOper[0x1000] = true;
                                this.OnMouseDoubleClick(args);
                                if ((args2.ColumnIndex < this.Columns.Count) && (args2.RowIndex < this.Rows.Count))
                                {
                                    this.OnCellMouseDoubleClick(args2);
                                }
                                break;

                            case DataGridViewMouseEvent.MouseDown:
                                this.OnMouseDown(args);
                                if ((args2.ColumnIndex < this.Columns.Count) && (args2.RowIndex < this.Rows.Count))
                                {
                                    this.OnCellMouseDown(args2);
                                }
                                break;
                        }
                        return;
                    }
                }
                if (this.dataGridViewOper[0x1000])
                {
                    if (e.Clicks == 2)
                    {
                        args = new MouseEventArgs(e.Button, 1, x, y, e.Delta);
                        args2 = new DataGridViewCellMouseEventArgs(info.col, info.row, localX, args.Y - info.RowY, args);
                    }
                    switch (dgvme)
                    {
                        case DataGridViewMouseEvent.DoubleClick:
                            dgvme = DataGridViewMouseEvent.Click;
                            break;

                        case DataGridViewMouseEvent.MouseDoubleClick:
                            dgvme = DataGridViewMouseEvent.MouseClick;
                            break;
                    }
                }
                switch (dgvme)
                {
                    case DataGridViewMouseEvent.Click:
                        this.OnClick(args);
                        if (((e.Button == MouseButtons.Left) && (args2.ColumnIndex < this.Columns.Count)) && (args2.RowIndex < this.Rows.Count))
                        {
                            this.OnCellClick(new DataGridViewCellEventArgs(args2.ColumnIndex, args2.RowIndex));
                        }
                        return;

                    case DataGridViewMouseEvent.DoubleClick:
                        this.OnDoubleClick(args);
                        if (((e.Button == MouseButtons.Left) && (args2.ColumnIndex < this.Columns.Count)) && (args2.RowIndex < this.Rows.Count))
                        {
                            this.OnCellDoubleClick(new DataGridViewCellEventArgs(args2.ColumnIndex, args2.RowIndex));
                        }
                        return;

                    case DataGridViewMouseEvent.MouseClick:
                        this.OnMouseClick(args);
                        if ((args2.ColumnIndex < this.Columns.Count) && (args2.RowIndex < this.Rows.Count))
                        {
                            this.OnCellMouseClick(args2);
                        }
                        return;

                    case DataGridViewMouseEvent.MouseDoubleClick:
                        this.OnMouseDoubleClick(args);
                        if ((args2.ColumnIndex < this.Columns.Count) && (args2.RowIndex < this.Rows.Count))
                        {
                            this.OnCellMouseDoubleClick(args2);
                        }
                        return;

                    case DataGridViewMouseEvent.MouseDown:
                        this.OnMouseDown(args);
                        if ((args2.ColumnIndex < this.Columns.Count) && (args2.RowIndex < this.Rows.Count))
                        {
                            this.OnCellMouseDown(args2);
                        }
                        return;

                    case DataGridViewMouseEvent.MouseUp:
                        if (this.dataGridViewState2[0x800000])
                        {
                            MouseEventArgs args3 = new MouseEventArgs(e.Button, 2, x, y, e.Delta);
                            args2 = new DataGridViewCellMouseEventArgs(args2.ColumnIndex, args2.RowIndex, args2.X, args2.Y, args3);
                        }
                        this.OnCellMouseUp(args2);
                        this.OnMouseUp(args);
                        return;

                    case DataGridViewMouseEvent.MouseMove:
                        this.OnCellMouseMove(args2);
                        return;
                }
            }
            finally
            {
                this.dataGridViewState2[0x8000000] = false;
            }
        }