Exemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        public CheckBoxColumnHeaderHandler(DataGridViewColumn col)
        {
            Debug.Assert(col != null);
            Debug.Assert(col is DataGridViewCheckBoxColumn);
            Debug.Assert(col.DataGridView != null);

            _col        = col;
            _owningGrid = col.DataGridView;
            _owningGrid.HandleDestroyed  += HandleHandleDestroyed;
            _owningGrid.CellPainting     += HandleHeaderCellPainting;
            _owningGrid.CellMouseMove    += HandleHeaderCellMouseMove;
            _owningGrid.CellMouseClick   += HandleHeaderCellMouseClick;
            _owningGrid.CellContentClick += HandleDataCellCellContentClick;
            _owningGrid.Scroll           += HandleGridScroll;
            _owningGrid.RowsAdded        += HandleGridRowsAdded;
            _owningGrid.RowsRemoved      += HandleGridRowsRemoved;

            if (!BetterGrid.CanPaintVisualStyle())
            {
                _szCheckBox = new Size(13, 13);
            }
            else
            {
                var element  = VisualStyleElement.Button.CheckBox.CheckedNormal;
                var renderer = new VisualStyleRenderer(element);
                using (var g = _owningGrid.CreateGraphics())
                    _szCheckBox = renderer.GetPartSize(g, ThemeSizeType.True);
            }
        }
Exemplo n.º 2
0
        /// ------------------------------------------------------------------------------------
        private void DrawMinimalistButton(Graphics g, Rectangle rc)
        {
            var element = GetVisualStyleComboButton();

            rc = AdjustRectToDefaultComboButtonWidth(rc);

            if (element != VisualStyleElement.ComboBox.DropDownButton.Normal &&
                element != VisualStyleElement.ComboBox.DropDownButton.Disabled &&
                BetterGrid.CanPaintVisualStyle(element))
            {
                var renderer = new VisualStyleRenderer(element);
                renderer.DrawBackground(g, rc);
            }
            else
            {
                var pen = (element == VisualStyleElement.ComboBox.DropDownButton.Disabled ?
                           SystemPens.GrayText : SystemPens.WindowText);

                var x = rc.X + (int)Math.Round((rc.Width - 7) / 2f, MidpointRounding.AwayFromZero);
                var y = rc.Y + (int)Math.Round((rc.Height - 4) / 2f, MidpointRounding.AwayFromZero);
                g.DrawLine(pen, x, y, x + 6, y++);
                g.DrawLine(pen, x + 1, y, x + 5, y++);
                g.DrawLine(pen, x + 2, y, x + 4, y);
                g.DrawLine(pen, x + 3, y, x + 3, y + 1);
                return;
            }
        }
Exemplo n.º 3
0
        /// ------------------------------------------------------------------------------------
        private bool DrawVisualStyledButton(PushButtonColumn.ButtonType buttonStyle,
                                            IDeviceContext g, Rectangle rcbtn)
        {
            VisualStyleElement element = (buttonStyle == PushButtonColumn.ButtonType.VisualStyleCombo ?
                                          GetVisualStyleComboButton() : GetVisualStylePushButton());

            if (!BetterGrid.CanPaintVisualStyle(element))
            {
                return(false);
            }

            VisualStyleRenderer renderer = new VisualStyleRenderer(element);

            rcbtn = AdjustRectToDefaultComboButtonWidth(rcbtn);
            renderer.DrawBackground(g, rcbtn);
            return(true);
        }
Exemplo n.º 4
0
        /// ------------------------------------------------------------------------------------
        private void HandleHeaderCellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.RowIndex >= 0 && e.ColumnIndex != _col.Index)
            {
                return;
            }

            var rcCell = _owningGrid.GetCellDisplayRectangle(_col.Index, -1, false);

            if (rcCell.IsEmpty)
            {
                return;
            }

            // At this point, we know at least part of the header cell is visible, therefore,
            // force the rectangle's width to that of the column's.
            rcCell.X = rcCell.Right - _col.Width;

            // Subtract one so as not to include the left border in the width.
            rcCell.Width = _col.Width - 1;

            int dx = (int)Math.Floor((rcCell.Width - _szCheckBox.Width) / 2f);
            int dy = (int)Math.Floor((rcCell.Height - _szCheckBox.Height) / 2f);
            var rc = new Rectangle(rcCell.X + dx, rcCell.Y + dy, _szCheckBox.Width, _szCheckBox.Height);

            if (BetterGrid.CanPaintVisualStyle())
            {
                DrawVisualStyleCheckBox(e.Graphics, rc);
            }
            else
            {
                var state = ButtonState.Checked;
                if (HeadersCheckState == CheckState.Unchecked)
                {
                    state = ButtonState.Normal;
                }
                else if (HeadersCheckState == CheckState.Indeterminate)
                {
                    state |= ButtonState.Inactive;
                }

                ControlPaint.DrawCheckBox(e.Graphics, rc, state | ButtonState.Flat);
            }
        }