/// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public CheckBoxColumnHeaderHandler(DataGridViewColumn col)
        {
            Debug.Assert(col != null);
            Debug.Assert(col is DataGridViewCheckBoxColumn);
            Debug.Assert(col.DataGridView != null);

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

            if (!PaintingHelper.CanPaintVisualStyle())
            {
                m_szCheckBox = new Size(13, 13);
            }
            else
            {
                var element  = VisualStyleElement.Button.CheckBox.CheckedNormal;
                var renderer = new VisualStyleRenderer(element);
                using (var g = m_grid.CreateGraphics())
                    m_szCheckBox = renderer.GetPartSize(g, ThemeSizeType.True);
            }
        }
Пример #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 &&
                PaintingHelper.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;
            }
        }
Пример #3
0
        /// ------------------------------------------------------------------------------------
        private bool DrawVisualStyledButton(SilButtonColumn.ButtonType buttonStyle,
                                            IDeviceContext g, Rectangle rcbtn)
        {
            VisualStyleElement element = (buttonStyle == SilButtonColumn.ButtonType.VisualStyleCombo ?
                                          GetVisualStyleComboButton() : GetVisualStylePushButton());

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

            VisualStyleRenderer renderer = new VisualStyleRenderer(element);

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

            var rcCell = m_grid.GetCellDisplayRectangle(m_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 - m_col.Width;

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

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

            if (PaintingHelper.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);
            }
        }