Ejemplo n.º 1
0
        private void SmoothTable_Paint(object sender, PaintEventArgs e)
        {
            m_dbgGraphics.CreateDoubleBuffer(e.Graphics, this.Width, this.Height);

            System.Drawing.Point ptDrawStart  = new Point(0, m_iColumnHeight);
            System.Drawing.Point ptDrawFinish = new Point(0, 0);
            System.Drawing.Point ptLabelPoint = new Point();
            System.Drawing.SizeF sfLabelSize;
            Region m_rgOrigRegion = m_dbgGraphics.g.Clip;

            m_dbgGraphics.g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            m_dbgGraphics.g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            m_iTotalHeight = 0;
            m_iTotalWidth  = 0;

            //draw rows, but not row lines - we don't know how wide the table is yet
            //while drawing, keep track of total height
            //also draw row labels
            for (int i = 0; i < m_lsRowLabels.Count; i++)
            {
                //draw background gradient of row label
                Gradient.DrawGradient(m_dbgGraphics.g, Gradient.GradientDirection.Vertical, m_cGradientStart, m_cGradientFinish, m_iRowWidth, m_lsRowLabels[i].Height, ptDrawStart);

                //draw row label
                m_lsRowLabels[i].Region = new Rectangle(ptDrawStart.X, ptDrawStart.Y, m_iRowWidth, m_lsRowLabels[i].Height);
                sfLabelSize             = m_dbgGraphics.g.MeasureString(m_lsRowLabels[i].Text, m_fntLabelFont);
                ptLabelPoint.X          = ptDrawStart.X + ((m_lsRowLabels[i].Region.Width / 2) - ((int)sfLabelSize.Width / 2));
                ptLabelPoint.Y          = ptDrawStart.Y + ((m_lsRowLabels[i].Region.Height / 2) - ((int)sfLabelSize.Height / 2));

                m_dbgGraphics.g.Clip = new Region(m_lsRowLabels[i].Region);
                m_dbgGraphics.g.DrawString(m_lsRowLabels[i].Text, m_fntLabelFont, m_bshLabelTextBrush, ptLabelPoint);
                m_dbgGraphics.g.Clip = m_rgOrigRegion;

                ptDrawStart.Y += m_lsRowLabels[i].Height;
            }

            //prepare start and end points
            m_iTotalHeight = ptDrawStart.Y;
            ptDrawFinish.Y = m_iTotalHeight;
            ptDrawStart.Y  = 0;
            ptDrawStart.X  = m_iRowWidth;

            //draw columns and column lines, build total width while you're at it
            for (int i = 0; i < m_lsColumnLabels.Count; i++)
            {
                Gradient.DrawGradient(m_dbgGraphics.g, Gradient.GradientDirection.Vertical, m_cGradientStart, m_cGradientFinish, m_lsColumnLabels[i].Width, m_iColumnHeight, ptDrawStart);

                //draw column label
                m_lsColumnLabels[i].Region = new Rectangle(ptDrawStart.X, ptDrawStart.Y, m_lsColumnLabels[i].Width, m_iColumnHeight);
                sfLabelSize    = m_dbgGraphics.g.MeasureString(m_lsColumnLabels[i].Text, m_fntLabelFont);
                ptLabelPoint.X = ptDrawStart.X + ((m_lsColumnLabels[i].Region.Width / 2) - ((int)sfLabelSize.Width / 2));
                ptLabelPoint.Y = ptDrawStart.Y + ((m_lsColumnLabels[i].Region.Height / 2) - ((int)sfLabelSize.Height / 2));

                m_dbgGraphics.g.Clip = new Region(m_lsColumnLabels[i].Region);
                m_dbgGraphics.g.DrawString(m_lsColumnLabels[i].Text, m_fntLabelFont, m_bshLabelTextBrush, ptLabelPoint);
                m_dbgGraphics.g.Clip = m_rgOrigRegion;

                //draw grid line
                ptDrawFinish.X = ptDrawStart.X;
                m_dbgGraphics.g.DrawLine(m_pGridPen, ptDrawStart, ptDrawFinish);

                ptDrawStart.X += m_lsColumnLabels[i].Width;
            }

            //prepare start and end points.
            //start point will be all the way to the right of the table,
            //end point will be on the left
            m_iTotalWidth  = ptDrawStart.X;
            ptDrawStart.Y  = m_iColumnHeight;
            ptDrawFinish.X = 0;
            ptDrawFinish.Y = ptDrawStart.Y;

            //draw final row lines now that total width has been calculated
            for (int i = 0; i < m_lsRowLabels.Count; i++)
            {
                m_dbgGraphics.g.DrawLine(m_pGridPen, ptDrawStart, ptDrawFinish);
                ptDrawStart.Y += m_lsRowLabels[i].Height;
                ptDrawFinish.Y = ptDrawStart.Y;
            }

            //final border around everything
            m_dbgGraphics.g.DrawRectangle(m_pGridPen, 0, 0, m_iTotalWidth, m_iTotalHeight);

            //final resize to match size of drawn table
            this.SmoothTable_Resize(this, EventArgs.Empty);

            Fill(m_dbgGraphics.g);

            m_dbgGraphics.Render(e.Graphics);
        }