XPTable.Models.Table.OnPaintHeader C# (CSharp) Method

OnPaintHeader() protected method

Paints the Table's Column headers
protected OnPaintHeader ( PaintEventArgs e ) : void
e PaintEventArgs A PaintEventArgs that contains the event data
return void
        protected void OnPaintHeader(PaintEventArgs e)
        {
            // only bother if we actually get to paint something
            if (!this.HeaderRectangle.IntersectsWith(e.ClipRectangle))
            {
                return;
            }

            int xPos = this.DisplayRectangleLeft;
            bool needDummyHeader = true;

            //
            PaintHeaderEventArgs phea = new PaintHeaderEventArgs(e.Graphics, e.ClipRectangle);

            for (int i = 0; i < this.ColumnModel.Columns.Count; i++)
            {
                // check that the column isn't hidden
                if (this.ColumnModel.Columns[i].Visible)
                {
                    Rectangle colHeaderRect = new Rectangle(xPos, this.BorderWidth, this.ColumnModel.Columns[i].Width, this.HeaderHeight);

                    // check that the column intersects with the clipping rect
                    if (e.ClipRectangle.IntersectsWith(colHeaderRect))
                    {
                        // move and resize the headerRenderer
                        this.headerRenderer.Bounds = new Rectangle(xPos, this.BorderWidth, this.ColumnModel.Columns[i].Width, this.HeaderHeight);

                        // set the clipping area to the header renderers bounds
                        phea.Graphics.SetClip(Rectangle.Intersect(e.ClipRectangle, this.headerRenderer.Bounds));

                        // draw the column header
                        phea.SetColumn(this.ColumnModel.Columns[i]);
                        phea.SetColumnIndex(i);
                        phea.SetTable(this);
                        phea.SetHeaderStyle(this.HeaderStyle);
                        phea.SetHeaderRect(this.headerRenderer.Bounds);

                        // let the user get the first crack at painting the header
                        this.OnBeforePaintHeader(phea);

                        // only send to the renderer if the user hasn't
                        // set the handled property
                        if (!phea.Handled)
                        {
                            this.headerRenderer.OnPaintHeader(phea);
                        }

                        // let the user have another go
                        this.OnAfterPaintHeader(phea);
                    }

                    // set the next column start position
                    xPos += this.ColumnModel.Columns[i].Width;

                    // if the next start poition is past the right edge
                    // of the clipping rectangle then we don't need to
                    // draw anymore
                    if (xPos >= e.ClipRectangle.Right)
                    {
                        return;
                    }

                    // check is the next column position is past the
                    // right edge of the table.  if it is, get out of
                    // here as we don't need to draw anymore columns
                    if (xPos >= this.ClientRectangle.Width)
                    {
                        needDummyHeader = false;

                        break;
                    }
                }
            }

            if (needDummyHeader)
            {
                // move and resize the headerRenderer
                this.headerRenderer.Bounds = new Rectangle(xPos, this.BorderWidth, this.ClientRectangle.Width - xPos + 2, this.HeaderHeight);

                phea.Graphics.SetClip(Rectangle.Intersect(e.ClipRectangle, this.headerRenderer.Bounds));

                phea.SetColumn(null);
                phea.SetColumnIndex(-1);
                phea.SetTable(this);
                phea.SetHeaderStyle(this.HeaderStyle);
                phea.SetHeaderRect(this.headerRenderer.Bounds);

                // let the user get the first crack at painting the header
                this.OnBeforePaintHeader(phea);

                // only send to the renderer if the user hasn't
                // set the handled property
                if (!phea.Handled)
                {
                    this.headerRenderer.OnPaintHeader(phea);
                }

                // let the user have another go
                this.OnAfterPaintHeader(phea);
            }
        }
Table