Ejemplo n.º 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             = this.GetItemRect(columnIndex);
            OLVColumn column        = this.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 = this.CalculateStyle(column, columnIndex == this.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 (this.ListView.HeaderUsesThemes &&
                VisualStyleRenderer.IsSupported &&
                VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.Item.Normal))
            {
                this.DrawThemedBackground(g, r, columnIndex, isPressed);
            }
            else
            {
                this.DrawUnthemedBackground(g, r, columnIndex, isPressed, stateStyle);
            }


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

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

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