示例#1
0
        /// <summary>
        /// Draw one cell of the header
        /// </summary>
        /// <param name="g"></param>
        /// <param name="columnIndex"></param>
        /// <param name="itemState"></param>
        protected void CustomDrawHeaderCell(Graphics g, int columnIndex, int itemState)
        {
            Rectangle r             = GetItemRect(columnIndex);
            OLVColumn column        = ListView.GetColumn(columnIndex);
            const int CDIS_SELECTED = 1;
            bool      isPressed     = ((itemState & CDIS_SELECTED) == CDIS_SELECTED);

            // Calculate which style should be used for the header
            HeaderStateStyle stateStyle = CalculateStyle(column, columnIndex == ColumnIndexUnderCursor, isPressed);

            // If there is an owner drawn delegate installed, give it a chance to draw the header
            if (column.HeaderDrawing != null)
            {
                if (!column.HeaderDrawing(g, r, columnIndex, column, isPressed, stateStyle))
                {
                    return;
                }
            }

            // Draw the background
            if (ListView.HeaderUsesThemes &&
                VisualStyleRenderer.IsSupported &&
                VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.Item.Normal))
            {
                DrawThemedBackground(g, r, columnIndex, isPressed);
            }
            else
            {
                DrawUnthemedBackground(g, r, columnIndex, isPressed, stateStyle);
            }


            // Draw the sort indicator if this column has one
            if (HasSortIndicator(column))
            {
                if (ListView.HeaderUsesThemes &&
                    VisualStyleRenderer.IsSupported &&
                    VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.SortArrow.SortedUp))
                {
                    DrawThemedSortIndicator(g, r);
                }
                else
                {
                    r = DrawUnthemedSortIndicator(g, r);
                }
            }

            if (HasFilterIndicator(column))
            {
                r = DrawFilterIndicator(g, r);
            }

            // Finally draw the text
            DrawHeaderImageAndText(g, r, column, stateStyle);
        }
        /// <summary>
        /// Draw one cell of the header
        /// </summary>
        /// <param name="g"></param>
        /// <param name="columnIndex"></param>
        /// <param name="itemState"></param>
        protected void CustomDrawHeaderCell(Graphics g, int columnIndex, int itemState)
        {
            OLVColumn column = ListView.GetColumn(columnIndex);

            bool hasCheckBox           = HasCheckBox(column);
            bool isMouseOverCheckBox   = columnIndex == lastCheckBoxUnderCursor;
            bool isMouseDownOnCheckBox = isMouseOverCheckBox && Control.MouseButtons == MouseButtons.Left;
            bool isHot = (columnIndex == ColumnIndexUnderCursor) && (!(hasCheckBox && isMouseOverCheckBox));

            const int CDIS_SELECTED = 1;
            bool      isPressed     = ((itemState & CDIS_SELECTED) == CDIS_SELECTED);

            // System.Diagnostics.Debug.WriteLine(String.Format("{2:hh:mm:ss.ff} - HeaderCustomDraw: {0}, {1}", columnIndex, itemState, DateTime.Now));

            // Calculate which style should be used for the header
            HeaderStateStyle stateStyle = CalculateStateStyle(column, isHot, isPressed);

            // If there is an owner drawn delegate installed, give it a chance to draw the header
            Rectangle fullCellBounds = GetItemRect(columnIndex);

            if (column.HeaderDrawing != null)
            {
                if (!column.HeaderDrawing(g, fullCellBounds, columnIndex, column, isPressed, stateStyle))
                {
                    return;
                }
            }

            // Draw the background
            if (ListView.HeaderUsesThemes &&
                VisualStyleRenderer.IsSupported &&
                VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.Item.Normal))
            {
                DrawThemedBackground(g, fullCellBounds, columnIndex, isPressed, isHot);
            }
            else
            {
                DrawUnthemedBackground(g, fullCellBounds, columnIndex, isPressed, isHot, stateStyle);
            }

            Rectangle r = GetHeaderDrawRect(columnIndex);

            // Draw the sort indicator if this column has one
            if (HasSortIndicator(column))
            {
                if (ListView.HeaderUsesThemes &&
                    VisualStyleRenderer.IsSupported &&
                    VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.SortArrow.SortedUp))
                {
                    DrawThemedSortIndicator(g, r);
                }
                else
                {
                    r = DrawUnthemedSortIndicator(g, r);
                }
            }

            if (hasCheckBox)
            {
                r = DrawCheckBox(g, r, column.HeaderCheckState, column.HeaderCheckBoxDisabled, isMouseOverCheckBox, isMouseDownOnCheckBox);
            }

            // Debugging - Where is the text going to be drawn
            //            g.DrawRectangle(Pens.Blue, r);

            // Finally draw the text
            DrawHeaderImageAndText(g, r, column, stateStyle);
        }