Beispiel #1
0
        protected void DrawHeaderText(Graphics g, Rectangle r, OLVColumn column, HeaderStateStyle stateStyle)
        {
            TextFormatFlags flags = this.TextFormatFlags;

            if (column.TextAlign == HorizontalAlignment.Center)
            {
                flags |= TextFormatFlags.HorizontalCenter;
            }
            if (column.TextAlign == HorizontalAlignment.Right)
            {
                flags |= TextFormatFlags.Right;
            }

            Font  f     = this.ListView.HeaderUsesThemes ? this.ListView.Font : stateStyle.Font ?? this.ListView.Font;
            Color color = this.ListView.HeaderUsesThemes ? Color.Black : stateStyle.ForeColor;

            if (color.IsEmpty)
            {
                color = Color.Black;
            }

            // Tweak the text rectangle a little to improve aethestics
            r.Inflate(-3, 0);
            r.Y -= 2;

            TextRenderer.DrawText(g, column.Text, f, r, color, Color.Transparent, flags);
        }
Beispiel #2
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);

            // 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);
                }
            }

            // Finally draw the text
            this.DrawHeaderText(g, r, column, stateStyle);
        }
Beispiel #3
0
        private bool NeedsCustomDraw(HeaderStateStyle style)
        {
            if (style == null)
            {
                return(false);
            }

            // If we want fancy colors or frames, we have to custom draw. Oddly enough, we
            // can handle font changes without custom drawing.
            if (!style.BackColor.IsEmpty)
            {
                return(true);
            }

            if (style.FrameWidth > 0f && !style.FrameColor.IsEmpty)
            {
                return(true);
            }

            return(!style.ForeColor.IsEmpty && style.ForeColor != Color.Black);
        }
Beispiel #4
0
        protected Font CalculateFont(OLVColumn column, bool isHot, bool isPressed)
        {
            HeaderStateStyle stateStyle = this.CalculateStyle(column, isHot, isPressed);

            return(stateStyle.Font ?? this.ListView.Font);
        }
Beispiel #5
0
        protected void DrawUnthemedBackground(Graphics g, Rectangle r, int columnIndex, bool isSelected, HeaderStateStyle stateStyle)
        {
            if (stateStyle.BackColor.IsEmpty)
            {
                // I know we're supposed to be drawing the unthemed background, but let's just see if we
                // can draw something more interesting than the dull raised block
                if (VisualStyleRenderer.IsSupported &&
                    VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.Item.Normal))
                {
                    this.DrawThemedBackground(g, r, columnIndex, isSelected);
                }
                else
                {
                    ControlPaint.DrawBorder3D(g, r, Border3DStyle.RaisedInner);
                }
            }
            else
            {
                using (Brush b = new SolidBrush(stateStyle.BackColor))
                    g.FillRectangle(b, r);
            }

            // Draw the frame if the style asks for one
            if (!stateStyle.FrameColor.IsEmpty && stateStyle.FrameWidth > 0f)
            {
                RectangleF r2 = r;
                r2.Inflate(-stateStyle.FrameWidth, -stateStyle.FrameWidth);
                g.DrawRectangle(new Pen(stateStyle.FrameColor, stateStyle.FrameWidth),
                                r2.X, r2.Y, r2.Width, r2.Height);
            }
        }
        protected void DrawHeaderText(Graphics g, Rectangle r, OLVColumn column, HeaderStateStyle stateStyle) {
            TextFormatFlags flags = this.TextFormatFlags;
            if (column.TextAlign == HorizontalAlignment.Center)
                flags |= TextFormatFlags.HorizontalCenter;
            if (column.TextAlign == HorizontalAlignment.Right)
                flags |= TextFormatFlags.Right;

            Font f = this.ListView.HeaderUsesThemes ? this.ListView.Font : stateStyle.Font ?? this.ListView.Font;
            Color color = this.ListView.HeaderUsesThemes ? Color.Black : stateStyle.ForeColor;
            if (color.IsEmpty)
                color = Color.Black;

            // Tweak the text rectangle a little to improve aethestics
            r.Inflate(-3, 0);
            r.Y -= 2;

            TextRenderer.DrawText(g, column.Text, f, r, color, Color.Transparent, flags);
        }
        protected void DrawUnthemedBackground(Graphics g, Rectangle r, int columnIndex, bool isSelected, HeaderStateStyle stateStyle) {
            if (stateStyle.BackColor.IsEmpty)
                // I know we're supposed to be drawing the unthemed background, but let's just see if we
                // can draw something more interesting than the dull raised block
                if (VisualStyleRenderer.IsSupported &&
                    VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.Item.Normal))
                    this.DrawThemedBackground(g, r, columnIndex, isSelected);
                else
                    ControlPaint.DrawBorder3D(g, r, Border3DStyle.RaisedInner);
            else {
                using (Brush b = new SolidBrush(stateStyle.BackColor))
                    g.FillRectangle(b, r);
            }

            // Draw the frame if the style asks for one
            if (!stateStyle.FrameColor.IsEmpty && stateStyle.FrameWidth > 0f) {
                RectangleF r2 = r;
                r2.Inflate(-stateStyle.FrameWidth, -stateStyle.FrameWidth);
                g.DrawRectangle(new Pen(stateStyle.FrameColor, stateStyle.FrameWidth), 
                    r2.X, r2.Y, r2.Width, r2.Height);
            }
        }
        private bool NeedsCustomDraw(HeaderStateStyle style) {
            if (style == null)
                return false;

            // If we want fancy colors or frames, we have to custom draw. Oddly enough, we 
            // can handle font changes without custom drawing.
            if (!style.BackColor.IsEmpty)
                return true;
            
            if (style.FrameWidth > 0f && !style.FrameColor.IsEmpty)
                return true;

            return (!style.ForeColor.IsEmpty && style.ForeColor != Color.Black);
        }