コード例 #1
0
        public override void OnMouseDown(MouseEventArgs e)
        {
            if (!Enabled)
            {
                return;
            }

            if (DropDownButtonBounds.Contains(e.X, e.Y))
            {
                _dropDownPressed = true;

                if (_dropDownVisible)
                {
                    HideDropDown();
                }
                else if (this.DropDownItems.Count > 0)
                {
                    ShowDropDown();
                }
            }
            else if (TextBoxBounds.Contains(e.X, e.Y) && AllowTextEdit)
            {
                StartEdit();
            }
        }
コード例 #2
0
        /// <summary>
        /// Handles mouse clicks to the header cell, displaying the
        /// drop-down list or sorting the owning column as appropriate.
        /// </summary>
        /// <param name="e">A DataGridViewCellMouseEventArgs that contains the event data.</param>
        protected override void OnMouseDown(DataGridViewCellMouseEventArgs e)
        {
            Debug.Assert(DataGridView != null, "DataGridView is null");

            // this allows the menu to close when the user clicks on the button again
            if (!m_intervalElapsed)
            {
                return;
            }

            // retrieve the current size and location of the header cell, excluding any portion that is scrolled off screen.
            var cellBounds = DataGridView.GetCellDisplayRectangle(e.ColumnIndex, -1, false);

            // Continue only if the mouse coordinates are not within the column resize zone.
            if (((DataGridView.RightToLeft == RightToLeft.No && cellBounds.Width - e.X < 6) || e.X < 6))
            {
                return;
            }

            // unless RightToLeft is enabled, store the width of the portion that is scrolled off screen.
            var scrollingOffset = 0;

            if (DataGridView.RightToLeft == RightToLeft.No && DataGridView.FirstDisplayedScrollingColumnIndex == ColumnIndex)
            {
                scrollingOffset = DataGridView.FirstDisplayedScrollingColumnHiddenWidth;
            }

            // Show the drop-down list if the mouse click occurred within the drop-down button bounds.
            // Otherwise, if sorting is enabled and the click occurred outside the drop-down button bounds, sort by the owning column.
            // The mouse coordinates are relative to the cell bounds.
            if (DropDownButtonBounds.Contains(e.X + cellBounds.Left - scrollingOffset, e.Y + cellBounds.Top))
            {
                // If the current cell is in edit mode, commit the edit.
                if (DataGridView.IsCurrentCellInEditMode)
                {
                    // Commit and end the cell edit.
                    DataGridView.EndEdit();

                    // Commit any change to the underlying data source.
                    var source = DataGridView.DataSource as BindingSource;
                    if (source != null)
                    {
                        source.EndEdit();
                    }
                }

                var showAt = cellBounds.Location;
                showAt.Y += cellBounds.Height;
                showAt.X -= m_dropdownMenu.Width - cellBounds.Width;
                m_dropdownMenu.Show(DataGridView.PointToScreen(showAt));

                // Set the size and location of dropDownListBox, then display it.
                m_dropDownListBoxShowing = true;

                // Invalidate the cell so that the drop-down button will repaint in the pressed state.
                DataGridView.InvalidateCell(this);
            }

            base.OnMouseDown(e);
        }
コード例 #3
0
        /// <include file='doc\ToolStripComboButton.uex' path='docs/doc[@for="ToolStripSplitButton.OnMouseUp"]/*' />
        /// <devdoc>
        /// Summary of OnMouseUp.
        /// </devdoc>
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (!Enabled)
            {
                return;
            }


            SplitButtonButton.Push(false);

            if (DropDownButtonBounds.Contains(e.Location))
            {
                if (e.Button == MouseButtons.Left)
                {
                    if (DropDown.Visible)
                    {
                        Debug.Assert(ParentInternal != null, "Parent is null here, not going to get accurate ID");
                        byte closeMouseId = (ParentInternal == null) ? (byte)0: ParentInternal.GetMouseId();
                        if (closeMouseId != openMouseId)
                        {
                            openMouseId = 0;  // reset the mouse id, we should never get this value from toolstrip.
                            ToolStripManager.ModalMenuFilter.CloseActiveDropDown(DropDown, ToolStripDropDownCloseReason.AppClicked);
                            Select();
                        }
                    }
                }
            }
            Point clickPoint = new Point(e.X, e.Y);

            if ((e.Button == MouseButtons.Left) && this.SplitButtonButton.Bounds.Contains(clickPoint))
            {
                bool shouldFireDoubleClick = false;
                if (DoubleClickEnabled)
                {
                    long newTime    = DateTime.Now.Ticks;
                    long deltaTicks = newTime - lastClickTime;
                    lastClickTime = newTime;
                    // use >= for cases where the succession of click events is so fast it's not picked up by
                    // DateTime resolution.
                    Debug.Assert(deltaTicks >= 0, "why are deltaticks less than zero? thats some mighty fast clicking");
                    // if we've seen a mouse up less than the double click time ago, we should fire.
                    if (deltaTicks >= 0 && deltaTicks < DoubleClickTicks)
                    {
                        shouldFireDoubleClick = true;
                    }
                }
                if (shouldFireDoubleClick)
                {
                    OnButtonDoubleClick(new System.EventArgs());
                    // VSWhidbey 486983: if we actually fired DoubleClick - reset the lastClickTime.
                    lastClickTime = 0;
                }
                else
                {
                    OnButtonClick(new System.EventArgs());
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// Hides the drop-down list when it loses focus.
 /// </summary>
 /// <param name="sender">The object that raised the event.</param>
 /// <param name="e">An EventArgs that contains the event data.</param>
 private void DropDownListBox_LostFocus(object sender, EventArgs e)
 {
     // If the focus was lost because the user clicked the drop-down
     // button, store a value that prevents the subsequent OnMouseDown
     // call from displaying the drop-down list again.
     if (DropDownButtonBounds.Contains(
             this.DataGridView.PointToClient(new Point(
                                                 Control.MousePosition.X, Control.MousePosition.Y))))
     {
         lostFocusOnDropDownButtonClick = true;
     }
     HideDropDownList();
 }
コード例 #5
0
        public override void OnMouseDown(MouseEventArgs e)
        {
            if (!Enabled)
            {
                return;
            }
            // Steve - if allowtextedit is false, allow the textbox to bring up the popup
            if (DropDownButtonBounds.Contains(e.X, e.Y) || (TextBoxBounds.Contains(e.X, e.Y) != AllowTextEdit))
            {
                _dropDownPressed = true;

                ShowDropDown();
            }
            else if (TextBoxBounds.Contains(e.X, e.Y) && AllowTextEdit)
            {
                StartEdit();
            }
        }
コード例 #6
0
 /// <include file='doc\ToolStripComboButton.uex' path='docs/doc[@for="ToolStripSplitButton.OnMouseDown"]/*' />
 /// <devdoc>
 /// Summary of OnMouseDown.
 /// </devdoc>
 protected override void OnMouseDown(MouseEventArgs e)
 {
     if (DropDownButtonBounds.Contains(e.Location))
     {
         if (e.Button == MouseButtons.Left)
         {
             if (!DropDown.Visible)
             {
                 Debug.Assert(ParentInternal != null, "Parent is null here, not going to get accurate ID");
                 openMouseId = (ParentInternal == null) ? (byte)0: ParentInternal.GetMouseId();
                 this.ShowDropDown(/*mousePress = */ true);
             }
         }
     }
     else
     {
         SplitButtonButton.Push(true);
     }
 }
コード例 #7
0
        public override void OnMouseDown(MouseEventArgs e)
        {
            Console.WriteLine("Hello World!22");
            if (!Enabled)
            {
                return;
            }

            if (DropDownButtonBounds.Contains(e.X, e.Y))
            {
                _dropDownPressed = true;

                ShowDropDown();
            }
            else if (TextBoxBounds.Contains(e.X, e.Y) && AllowTextEdit)
            {
                StartEdit();
            }
        }
コード例 #8
0
        /// <summary>
        /// 处理鼠标单击到标题单元格,显示下拉列表或按适当情况对拥有列进行排序。
        /// </summary>
        /// <param name="e">A DataGridViewCellMouseEventArgs that contains the event data.</param>
        protected override void OnMouseDown(DataGridViewCellMouseEventArgs e)
        {
            //检索标题单元格的当前大小和位置,不包括从屏幕滚动的任何部分。
            Rectangle cellBounds = DataGridView
                                   .GetCellDisplayRectangle(e.ColumnIndex, -1, false);

            //仅当列不可手动调整大小或鼠标坐标不在列调整大小区域时才继续。
            if (OwningColumn.Resizable == DataGridViewTriState.True &&
                ((DataGridView.RightToLeft == RightToLeft.No &&
                  cellBounds.Width - e.X < 6) || e.X < 6))
            {
                return;
            }

            //除非启用 RightToLeft,否则将存储从屏幕滚动的部分的宽度。
            Int32 scrollingOffset = 0;

            if (DataGridView.RightToLeft == RightToLeft.No &&
                DataGridView.FirstDisplayedScrollingColumnIndex ==
                ColumnIndex)
            {
                scrollingOffset =
                    DataGridView.FirstDisplayedScrollingColumnHiddenWidth;
            }

            //如果启用了筛选,并且鼠标单击发生在下拉按钮范围内,则显示下拉列表。
            //否则,如果启用排序并且单击发生在下拉按钮边界之外,则按拥有列排序。
            //鼠标坐标是相对于单元格边界的,因此需要单元格位置和滚动偏移来确定客户端坐标。
            if (FilteringEnabled &&
                DropDownButtonBounds.Contains(
                    e.X + cellBounds.Left - scrollingOffset, e.Y + cellBounds.Top))
            {
                ColEvent.run(e.ColumnIndex);
            }
            else if (AutomaticSortingEnabled &&
                     DataGridView.SelectionMode !=
                     DataGridViewSelectionMode.ColumnHeaderSelect)
            {
                SortByColumn();
            }

            base.OnMouseDown(e);
        }
コード例 #9
0
        public override void OnMouseMove(MouseEventArgs e)
        {
            Console.WriteLine("Hello World!");
            if (!Enabled)
            {
                return;
            }

            base.OnMouseMove(e);

            bool mustRedraw = false;

            if (DropDownButtonBounds.Contains(e.X, e.Y))
            {
                Owner.Cursor = Cursors.Default;

                mustRedraw = !_dropDownSelected;

                _dropDownSelected = true;
            }
            else if (TextBoxBounds.Contains(e.X, e.Y))
            {
                Owner.Cursor = Cursors.IBeam;

                mustRedraw = _dropDownSelected;

                _dropDownSelected = false;
            }
            else
            {
                Owner.Cursor = Cursors.Default;
            }

            if (mustRedraw)
            {
                RedrawItem();
            }
        }
コード例 #10
0
        public override void OnMouseMove(MouseEventArgs e)
        {
            if (!Enabled)
            {
                return;
            }

            base.OnMouseMove(e);

            var mustRedraw = false;

            if (DropDownButtonBounds.Contains(e.X, e.Y))
            {
                Owner.Cursor = Cursors.Default;

                mustRedraw = !_dropDownSelected;

                _dropDownSelected = true;
            }
            else if (TextBoxBounds.Contains(e.X, e.Y))
            {
                Owner.Cursor = AllowTextEdit ? Cursors.IBeam : Cursors.Default;

                mustRedraw = _dropDownSelected;

                _dropDownSelected = false;
            }
            else
            {
                Owner.Cursor = Cursors.Default;
            }

            if (mustRedraw)
            {
                RedrawItem();
            }
        }
コード例 #11
0
        /// <summary>
        /// Handles mouse clicks to the header cell, displaying the
        /// drop-down list or sorting the owning column as appropriate.
        /// </summary>
        /// <param name="e">A DataGridViewCellMouseEventArgs that contains the event data.</param>
        protected override void OnMouseDown(DataGridViewCellMouseEventArgs e)
        {
            Debug.Assert(this.DataGridView != null, "DataGridView is null");

            // Continue only if the user did not click the drop-down button
            // while the drop-down list was displayed. This prevents the
            // drop-down list from being redisplayed after being hidden in
            // the LostFocus event handler.
            if (lostFocusOnDropDownButtonClick)
            {
                lostFocusOnDropDownButtonClick = false;
                return;
            }

            // Retrieve the current size and location of the header cell,
            // excluding any portion that is scrolled off screen.
            Rectangle cellBounds = this.DataGridView
                                   .GetCellDisplayRectangle(e.ColumnIndex, -1, false);

            // Continue only if the column is not manually resizable or the
            // mouse coordinates are not within the column resize zone.
            if (this.OwningColumn.Resizable == DataGridViewTriState.True &&
                ((this.DataGridView.RightToLeft == RightToLeft.No &&
                  cellBounds.Width - e.X < 6) || e.X < 6))
            {
                return;
            }

            // Unless RightToLeft is enabled, store the width of the portion
            // that is scrolled off screen.
            Int32 scrollingOffset = 0;

            if (this.DataGridView.RightToLeft == RightToLeft.No &&
                this.DataGridView.FirstDisplayedScrollingColumnIndex == this.ColumnIndex)
            {
                scrollingOffset = this.DataGridView.FirstDisplayedScrollingColumnHiddenWidth;
            }

            // Show the drop-down list if filtering is enabled and the mouse click occurred
            // within the drop-down button bounds. Otherwise, if sorting is enabled and the
            // click occurred outside the drop-down button bounds, sort by the owning column.
            // The mouse coordinates are relative to the cell bounds, so the cell location
            // and the scrolling offset are needed to determine the client coordinates.
            if (DropDownButtonBounds.Contains(e.X + cellBounds.Left - scrollingOffset, e.Y + cellBounds.Top))
            {
                // If the current cell is in edit mode, commit the edit.
                if (this.DataGridView.IsCurrentCellInEditMode)
                {
                    // Commit and end the cell edit.
                    this.DataGridView.EndEdit();

                    // Commit any change to the underlying data source.
                    if (this.DataGridView.DataSource is BindingSource source)
                    {
                        source.EndEdit();
                    }
                }
                ShowDropDownList();
            }

            base.OnMouseDown(e);
        }