Ejemplo n.º 1
0
        /// <summary>
        /// Print single line or multi lines TextBox.
        /// </summary>
        public void PrintTextBox(System.Windows.Forms.Control c,
            ParentControlPrinting typePrint,
            MultiPageManagement mp,
            Single x, Single y,
            ref Single extendedHeight, out bool ScanForChildControls)
        {
            ScanForChildControls = false;

            TextBox tb = (System.Windows.Forms.TextBox) c;
            Single h = mp.FontHeight(new Font(tb.Font.Name, tb.Font.Size));
            if (!tb.Multiline)
            {
                extendedHeight = mp.BeginPrintUnit(y, h);
                PrintText(c, mp, x, y, TextBoxBoxed, tb.Font.Bold, TextBoxBoxed, tb.TextAlign);
                mp.EndPrintUnit();
            }
            else  //multiline
            {
                // cut text into lines that fit in printed textBox width
                // Define an area of one line height and call MeasureString on it
                // This method return charactersFitted for the line
                ArrayList lines = new ArrayList();
                System.Drawing.Graphics g = mp.Graphics();
                SizeF areaForOneLineOfText = new SizeF();
                areaForOneLineOfText.Height = h;
                areaForOneLineOfText.Width = tb.Width;
                int charactersFitted;
                int linesFilled;
                int separatorCharPos;
                Font printFont = new Font(tb.Font.Name, tb.Font.Size);

                int pos = 0;
                do
                {
                    g.MeasureString(tb.Text.Substring(pos),
                        printFont,
                        areaForOneLineOfText,
                        new StringFormat(),
                        out charactersFitted,
                        out	linesFilled);
                    // this method with one line cut the last word....
                    // So, I have to go bak in the string to find a separator
                    // Happyly, MeasureString count separator character in charactersFitted
                    // For example, return "this is the first line " with space at the end
                    // even if there is not room for last space
                    separatorCharPos = charactersFitted;
                    if (charactersFitted < tb.Text.Substring(pos).Length) //le restant n'entre pas au complet sur la ligne
                    {
                        do
                        { separatorCharPos --; }
                        while ((separatorCharPos > pos) && !System.Char.IsSeparator(tb.Text, pos + separatorCharPos));
                        if (separatorCharPos == pos)   // no separator
                            separatorCharPos = charactersFitted;
                        else
                            separatorCharPos ++;
                    }
                    lines.Add(tb.Text.Substring(pos, separatorCharPos));
                    pos += separatorCharPos;
                }
                while ((pos < tb.Text.Length) && (charactersFitted > 0));

                // Print lines one by one
                Single yItem = y;
                Single extraHeight;
                Single extraHeightFirstLine = 0;	//Remenber if first line is pull down
                for (int i=0; i < lines.Count; i++)
                {
                    extraHeight = mp.BeginPrintUnit(yItem, h);   //Space required for tab page caption
                    if (i == 0)
                        extraHeightFirstLine = extraHeight;
                    mp.DrawString((string) lines[i], printFont, _Brush, x, yItem, tb.Width, h);
                    mp.EndPrintUnit();
                    yItem += h + extraHeight;
                }

                if ((yItem - y) > tb.Height)
                    extendedHeight = (yItem - y) - tb.Height;

                if (TextBoxBoxed)
                {
                    _Pen = new Pen(Color.Gray);
                    //Draw a rectangle arround list box. Start downer if first line pulled down
                    mp.DrawFrame(_Pen, x, y + extraHeightFirstLine, tb.Width, tb.Height + extendedHeight - extraHeightFirstLine);
                }
            }
        }
Ejemplo n.º 2
0
        public void PrintReportTitle(System.Windows.Forms.Control c,
            ParentControlPrinting typePrint,
            MultiPageManagement mp,
            Single x, Single y,
            ref Single extendedHeight, out bool ScanForChildControls)
        {
            ScanForChildControls = false;
            Font printFont = new Font(c.Font.Name, (Single) (c.Font.Size * 1.3), FontStyle.Bold);
            float fontHeight =  mp.FontHeight(printFont);
            Pen pen = new Pen(Color.Black, 2);
            extendedHeight = fontHeight + 3 + pen.Width + 1;

            mp.BeginPrintUnit(y, extendedHeight);
            mp.DrawString(c.Tag.ToString(), printFont, Brushes.Black, x, y, c.Width, fontHeight);
            y += fontHeight + 3;
            mp.DrawLines(pen, x, y, x + c.Size.Width, y);
            mp.EndPrintUnit();
        }
Ejemplo n.º 3
0
 public void PrintTabControl(System.Windows.Forms.Control c,
     ParentControlPrinting typePrint,
     MultiPageManagement mp,
     Single x, Single y,
     ref Single extendedHeight, out bool ScanForChildControls)
 {
     ScanForChildControls = true;
     System.Windows.Forms.TabControl tc = (TabControl) c;
     _Pen = new Pen(Color.Gray);
     switch (typePrint)
     {
         case ParentControlPrinting.BeforeChilds :
             //Nom du TabPage
             Single extraHeight = mp.BeginPrintUnit(y, tc.ItemSize.Height);   //Space required for tab page caption
             System.Windows.Forms.TabPage tp = tc.SelectedTab;
             Font printFont = new Font(tp.Font.Name, tp.Font.Size, FontStyle.Bold);
             Single h = mp.FontHeight(printFont);
             if (h > tc.ItemSize.Height)
                 h = tc.ItemSize.Height;
             mp.DrawString(tp.Text, printFont, Brushes.Black, x, y + (tc.ItemSize.Height - h) / 2, tp.Width, h);
             mp.DrawLines(_Pen, x, y + tc.ItemSize.Height, x + tc.Width, y + tc.ItemSize.Height);
             mp.EndPrintUnit();
             extendedHeight += extraHeight;
             break;
         case ParentControlPrinting.AfterChilds :
             if (TabControlBoxed)
                 mp.DrawFrame(_Pen, x, y, c.Width, c.Height + extendedHeight);
             break;
     }
 }
Ejemplo n.º 4
0
 public void PrintPictureBox(System.Windows.Forms.Control c,
     ParentControlPrinting typePrint,
     MultiPageManagement mp,
     Single x, Single y,
     ref Single extendedHeight, out bool ScanForChildControls)
 {
     ScanForChildControls = false;
     extendedHeight = mp.BeginPrintUnit(y, c.Height);
     PictureBox pic = (PictureBox) c;
     mp.DrawImage(pic.Image, x, y, c.Width, c.Height);
     mp.EndPrintUnit();
 }
Ejemplo n.º 5
0
 public void PrintRadioButton(System.Windows.Forms.Control c,
     ParentControlPrinting typePrint,
     MultiPageManagement mp,
     Single x, Single y,
     ref Single extendedHeight, out bool ScanForChildControls)
 {
     ScanForChildControls = false;
     Single h = mp.FontHeight(new Font(c.Font.Name, c.Font.Size));
     extendedHeight = mp.BeginPrintUnit(y, h);
     mp.DrawEllipse(_Pen, x, y, h, h);
     if ( ((RadioButton) c).Checked)
     {
         Single d = 3;
         mp.FillEllipse(_Brush, x + d, y + d, h - d - d, h - d - d);
     }
     PrintText(c, mp, (float) (x + (h * 1.4)), y - 2, false, false, false, HorizontalAlignment.Left);
     mp.EndPrintUnit();
 }
Ejemplo n.º 6
0
        public void PrintListBox(System.Windows.Forms.Control c,
            ParentControlPrinting typePrint,
            MultiPageManagement mp,
            Single x, Single y,
            ref Single extendedHeight, out bool ScanForChildControls)
        {
            ScanForChildControls = false;
            ListBox lb = (ListBox) c;
            Single yItem = y;
            Single extraHeight;
            Single extraHeightFirstLine = 0;	//Remenber if first line is pull down
            Font printFont = new Font(lb.Font.Name, lb.Font.Size, FontStyle.Bold);

            int oldPos = lb.SelectedIndex; //save position
            for (int i = 0; i < lb.Items.Count; i++)
            {
                extraHeight = mp.BeginPrintUnit(yItem, lb.ItemHeight);   //Space required for tab page caption
                if (i == 0)
                    extraHeightFirstLine = extraHeight;
                lb.SelectedIndex = i; // set position to obtain Text of current item
                mp.DrawString(lb.Text, printFont, _Brush, x, yItem, lb.Width, lb.ItemHeight);
                mp.EndPrintUnit();
                yItem += lb.ItemHeight + extraHeight;
            }
            lb.SelectedIndex = oldPos; //restore position

            if ((yItem - y) > lb.Height)
                extendedHeight = (yItem - y) - lb.Height;

            _Pen = new Pen(Color.Gray);
            //Draw a rectangle arround list box. Start downer if first line pulled down
            mp.DrawFrame(_Pen, x, y + extraHeightFirstLine, c.Width, c.Height + extendedHeight - extraHeightFirstLine);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Print a control (not is children). Call the print function depending of the type of the control
        /// </summary>
        /// <param name="c"></param>
        /// <param name="mp"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="extendedHeight"></param>
        public void PrintOneControl(System.Windows.Forms.Control c,
            ParentControlPrinting typePrint,
            MultiPageManagement mp,
            Single x, Single y,
            ref Single extendedHeight, out bool ScanForChildControls)
        {
            // Silver color if disable
            if (c.Enabled || !DisabledControlsInGray)
            {
                _Pen = new Pen(Color.Black);
                _Brush = Brushes.Black;
            }
            else
            {
                _Pen = new Pen(Color.Silver);
                _Brush = Brushes.Silver;
            }

            ScanForChildControls = true;
            string s = c.GetType().ToString();
            bool founded = false;
            //First check if it's a text box like control
            if (!founded)
                foreach (string sType in _TextBoxLikeControl)
                    if (s.IndexOf(sType) >= 0)
                    {
                        Single h;
                        h = mp.FontHeight(new Font(c.Font.Name, c.Font.Size));
                        extendedHeight = mp.BeginPrintUnit(y, h);
                        PrintText(c, mp, x, y, TextBoxBoxed, false, TextBoxBoxed, HorizontalAlignment.Left);
                        mp.EndPrintUnit();
                        founded = true;
                        ScanForChildControls = false;
                        break;
                    }

            //Process other type of control, beginning at the end of the list (use last add for a type)
            if (!founded)
                for (int i = _DelegatesforControls.Count-1; i>=0; i--)  // from end to the beginning
                {
                    _DelegateforControls d = (_DelegateforControls) _DelegatesforControls[i];
                    if (s.EndsWith(d.typ))
                    {
                        d.PrintFunction(c, typePrint, mp, x, y, ref extendedHeight, out ScanForChildControls);
                        break;
                    }
                }
            _traceLog.Append(_indent.ToString() + " - " + typePrint.ToString() + "  " + s + " (" + c.Text + ":" + c.Name + ")  X=" + x.ToString() +  "   Y=" + y.ToString() + "   H=" + c.Height.ToString() + "   + " + extendedHeight.ToString()+ System.Environment.NewLine);
        }
Ejemplo n.º 8
0
 /*public void PrintPanel(System.Windows.Forms.Control c,
     ParentControlPrinting typePrint,
     MultiPageManagement mp,
     Single x, Single y,
     ref Single extendedHeight, out bool ScanForChildControls)
 {
     ScanForChildControls = true;
     if (typePrint == ParentControlPrinting.AfterChilds)
         if ( ((System.Windows.Forms.Panel) c).BorderStyle != BorderStyle.None)
         {
             if (((System.Windows.Forms.Panel) c).BorderStyle == BorderStyle.Fixed3D)
                 _Pen = new Pen(Color.Silver);
             // if height less than 10, just print an horizontal line
             if ((c.Height < 10) && (c.Controls.Count == 0))
             {
                 extendedHeight += mp.BeginPrintUnit(y, 1);
                 mp.DrawLines(_Pen, x, y, x + c.Width, y);
                 mp.EndPrintUnit();
             }
             else
                 mp.DrawFrame(_Pen, x, y, c.Width, c.Height + extendedHeight);
         }
 }*/
 public void PrintGroupBox(System.Windows.Forms.Control c,
     ParentControlPrinting typePrint,
     MultiPageManagement mp,
     Single x, Single y,
     ref Single extendedHeight, out bool ScanForChildControls)
 {
     ScanForChildControls = true;
     Font printFont = new Font(c.Font.Name, c.Font.Size);
     Single h = mp.FontHeight(printFont);
     _Pen = new Pen(Color.Silver);
     switch (typePrint)
     {
         case ParentControlPrinting.BeforeChilds :
             // if height less than 10, just print an horizontal line
             if ((c.Height < 10) && (c.Controls.Count == 0))
             {
                 extendedHeight += mp.BeginPrintUnit(y, 1);
                 mp.DrawLines(_Pen, x, y, x + c.Width, y);
                 mp.EndPrintUnit();
             }
             else
             {
                 Single extraHeight = mp.BeginPrintUnit(y, h);   //Space required for group caption
                 //PrintText(c, mp, x + h, y, false, true, false, HorizontalAlignment.Left);
                 mp.DrawString(c.Text, printFont, Brushes.Black, x + h, y, c.Width - h - h, h);
                 mp.EndPrintUnit();
                 extendedHeight += extraHeight;
             };
             break;
         case ParentControlPrinting.AfterChilds :
             mp.DrawFrame(_Pen, x, y, c.Width, c.Height + extendedHeight);
             break;
     }
 }
Ejemplo n.º 9
0
        public void PrintLabel(System.Windows.Forms.Control c,
            ParentControlPrinting typePrint,
            MultiPageManagement mp,
            Single x, Single y,
            ref Single extendedHeight, out bool ScanForChildControls)
        {
            ScanForChildControls = false;
            // Convert ContentAlignment (property of labels) to HorizontalAlignment (Left, center, Right)
            HorizontalAlignment ha ;
            string ss = c.Text;
            ContentAlignment ha2 = ((Label) c).TextAlign;
            switch (ha2)
            {
                case ContentAlignment.BottomLeft:
                    ha = HorizontalAlignment.Left;
                    break;
                case ContentAlignment.TopLeft:
                    ha = HorizontalAlignment.Left;
                    break;
                case ContentAlignment.MiddleLeft:
                    ha = HorizontalAlignment.Left;
                    break;

                case ContentAlignment.BottomCenter:
                    ha = HorizontalAlignment.Center;
                    break;
                case ContentAlignment.TopCenter:
                    ha = HorizontalAlignment.Center;
                    break;
                case ContentAlignment.MiddleCenter:
                    ha = HorizontalAlignment.Center;
                    break;

                case ContentAlignment.BottomRight:
                    ha = HorizontalAlignment.Right;
                    break;
                case ContentAlignment.TopRight:
                    ha = HorizontalAlignment.Right;
                    break;
                case ContentAlignment.MiddleRight:
                    ha = HorizontalAlignment.Right;
                    break;
                default:
                    ha = HorizontalAlignment.Left;
                    break;
            }
            Single h = mp.FontHeight(new Font(c.Font.Name, c.Font.Size));
            if (c.Height > h)
                h = c.Height;
            extendedHeight = mp.BeginPrintUnit(y, h);
            PrintText(c, mp, x, y, false, LabelInBold, false, ha);
            mp.EndPrintUnit();
        }
Ejemplo n.º 10
0
        public void PrintDataGrid(System.Windows.Forms.Control c,
            ParentControlPrinting typePrint,
            MultiPageManagement mp,
            Single x, Single y,
            ref Single extendedHeight, out bool ScanForChildControls)
        {
            ScanForChildControls = false;

            DataGrid dg = (DataGrid) c;
            Single extraHeight = 0;
            Single extraHeightHeaderLine = 0;
            Font printFont = new Font(dg.Font.Name, dg.Font.Size, FontStyle.Bold);
            Single h = mp.FontHeight(printFont);

            // Column header
            DataGridTableStyle myGridTableStyle;
            if (dg.TableStyles.Count == 0)
            {
                myGridTableStyle = new DataGridTableStyle();
                dg.TableStyles.Add(myGridTableStyle);
            }

            // Header of each column
            Single xPos = x;
            Single yPos = y;
            Single w;
            extraHeightHeaderLine = mp.BeginPrintUnit(yPos, h+1);  //Space required for header text
            for (int i = 0; i < dg.TableStyles[0].GridColumnStyles.Count; i++)
            {
                string caption = dg.TableStyles[0].GridColumnStyles[i].HeaderText;
                w = dg.TableStyles[0].GridColumnStyles[i].Width;
                if (xPos+w > x + dg.Width)
                    w = x + dg.Width - xPos;
                if (xPos < x + dg.Width)
                    mp.DrawString(caption, printFont, _Brush, xPos, yPos, w, h);
                if (i == 0)  // Draw horizontal line below header
                    mp.DrawLines(_Pen, x, yPos+h, x+dg.Width, yPos+h);
                xPos += w;
            }
            mp.EndPrintUnit();
            yPos += h + 1 + extraHeightHeaderLine;

            // Get dataTable displayed in DataGrid
            // This function only support DataGrid with DataTable as DataSource
            // This is the only case I code to obtain data in DataGrid
            DataTable dt = null;
            if (dg.DataSource is System.Data.DataTable)
                dt = (DataTable) dg.DataSource;
            else
                if ((dg.DataSource is System.Data.DataSet) && (dg.DataMember != null))
            {
                DataSet ds = (DataSet) dg.DataSource;
                if (ds.Tables.Contains(dg.DataMember))
                    dt = ds.Tables[dg.DataMember];
            }

            // Loop on DataRow, with embed loop on columns
            if (dt != null)
                foreach (DataRow dr in dt.Rows)
                {
                    extraHeight = mp.BeginPrintUnit(yPos, h);  //Space required for header text
                    xPos = x;
                    for (int i = 0; i < dg.TableStyles[0].GridColumnStyles.Count; i++)
                    {
                        string caption = dr[i].ToString();
                        w = dg.TableStyles[0].GridColumnStyles[i].Width;
                        if (xPos+w > x + dg.Width)
                            w = x + dg.Width - xPos;
                        if (xPos < x + dg.Width)
                            mp.DrawString(caption, printFont, _Brush, xPos, yPos, w, h);
                        xPos += w;
                    };
                    mp.EndPrintUnit();
                    yPos += h + extraHeight;
                }

            // Draw horizontal line at the bottom of DataGrid
            if (yPos < y + dg.Height + extraHeightHeaderLine)
                yPos = y + dg.Height + extraHeightHeaderLine;
            mp.BeginPrintUnit(yPos, 1);
            mp.DrawLines(_Pen, x, yPos, x+dg.Width, yPos);
            mp.EndPrintUnit();

            // Finally, Compute extendedHeight
            if ((yPos - y) > dg.Height)
                extendedHeight = (yPos - y) - dg.Height;
        }
Ejemplo n.º 11
0
        public void PrintCheckBox(System.Windows.Forms.Control c,
            ParentControlPrinting typePrint,
            MultiPageManagement mp,
            Single x, Single y,
            ref Single extendedHeight, out bool ScanForChildControls)
        {
            ScanForChildControls = false;
            Single h = mp.FontHeight(new Font(c.Font.Name, c.Font.Size));
            extendedHeight = mp.BeginPrintUnit(y, h);

            mp.DrawRectangle(_Pen, x, y, h, h);
            if ( ((CheckBox) c).Checked )
            {
                Single d = 3;
                mp.DrawLines(_Pen, x + d, y + d, x + h - d, y + h - d);
                PointF[] points2 = new PointF[] {new PointF(x + h - d, y + d), new PointF(x + d, y + h - d)};
                mp.DrawLines(_Pen, x + h - d, y + d, x + d, y + h - d);
            }
            PrintText(c, mp, (float) (x + (h * 1.4)), (float) y - 2, false, false, false, HorizontalAlignment.Left);
            mp.EndPrintUnit();
        }
        public void PrintReportTitle(System.Windows.Forms.Control c,
            ParentControlPrinting typePrint,
            MultiPageManagement mp,
            Single x, Single y,
            ref Single extendedHeight, out bool ScanForChildControls)
        {
            ScanForChildControls = false;
            Font printFont = new Font(c.Font.Name, (Single)(c.Font.Size * 1.3), FontStyle.Bold);
            float fontHeight = mp.FontHeight(printFont);
            Pen pen = new Pen(Color.Black, 2);
            extendedHeight = fontHeight + 3 + pen.Width + 1;
            BrickGraphics test = ps.Graph;
            test.Font = printFont;

            SizeF size = test.MeasureString(c.Tag.ToString());
            mp.BeginPrintUnit(y, extendedHeight);
            int xy = (int)ps.PageSettings.UsablePageSize.Width / 2;
            xy = xy - Convert.ToInt32(size.Width / 2);

            mp.DrawString(c.Tag.ToString(), printFont, Color.Black, xy, y, c.Width, fontHeight + 4);
            y += fontHeight + 10;
            mp.DrawLines(pen,0, y, ps.PageSettings.UsablePageRect.Width - 30, y);
            mp.EndPrintUnit();
        }
        public void PrintPanel(System.Windows.Forms.Control c,
			ParentControlPrinting typePrint, 
			MultiPageManagement mp, 
			Single x, Single y,
			ref Single extendedHeight, out bool ScanForChildControls)
        {
            ScanForChildControls = true;
            if (typePrint == ParentControlPrinting.AfterChilds)
                if ( ((System.Windows.Forms.Panel) c).BorderStyle != BorderStyle.None)
                {
                    if (((System.Windows.Forms.Panel) c).BorderStyle == BorderStyle.Fixed3D)
                        _Pen = new Pen(Color.Silver);
                    // if height less than 10, just print an horizontal line
                    if ((c.Height < 10) && (c.Controls.Count == 0))
                    {
                        extendedHeight += mp.BeginPrintUnit(y, 1);
                        mp.DrawLines(_Pen, x, y, x + c.Width, y);
                        mp.EndPrintUnit();
                    }
                    else
                        mp.DrawFrame(_Pen, x, y, c.Width, c.Height + extendedHeight);
                }
        }
Ejemplo n.º 14
0
        public void PrintGridView(DevExpress.XtraGrid.GridControl c,
            ParentControlPrinting typePrint,
            MultiPageManagement mp,
            Single x, Single y,
            ref Single extendedHeight, out bool ScanForChildControls)
        {
            ScanForChildControls = false;

            //DataTable dtbl = (DataTable) c.DataSource;
            DevExpress.XtraGrid.Views.Grid.GridView gv = (DevExpress.XtraGrid.Views.Grid.GridView)c.DefaultView;

            //DataGrid dg = (DataGrid) c;
            Single extraHeight = 0;
            Single extraHeightHeaderLine = 0;
            Font printFont = new Font(c.Font.Name, c.Font.Size, FontStyle.Bold);
            Single h = mp.FontHeight(printFont);

            // Column header
            //DataGridTableStyle myGridTableStyle;
            //if (dg.TableStyles.Count == 0)
            //{
            //	myGridTableStyle = new DataGridTableStyle();
            //	dg.TableStyles.Add(myGridTableStyle);
            //}

            // Header of each column
            Single xPos = x;
            Single yPos = y;
            Single w;
            extraHeightHeaderLine = mp.BeginPrintUnit(yPos, h+1);  //Space required for header text
            for (int i = 0; i < gv.Columns.Count; i++)
            {
                string caption = gv.Columns[i].Caption;
                w = gv.Columns[i].Width;
                if (xPos+w > x + c.Width)
                    w = x + c.Width - xPos;
                if (xPos < x + c.Width)
                    mp.DrawString(caption, printFont, _Brush, xPos, yPos, w, h);
                if (i == 0)  // Draw horizontal line below header
                    mp.DrawLines(_Pen, x, yPos+h, x+c.Width, yPos+h);
                xPos += w;
            }
            mp.EndPrintUnit();
            yPos += h + 1 + extraHeightHeaderLine;

            // Get dataTable displayed in DataGrid
            // This function only support DataGrid with DataTable as DataSource
            // This is the only case I code to obtain data in DataGrid
            //DataTable dt = null;
            //if (dg.DataSource is System.Data.DataTable)
            //	dt = (DataTable) dg.DataSource;
            //else
            //	if ((dg.DataSource is System.Data.DataSet) && (dg.DataMember != null))
            //{
            //	DataSet ds = (DataSet) dg.DataSource;
            //	if (ds.Tables.Contains(dg.DataMember))
            //		dt = ds.Tables[dg.DataMember];
            //}

            // Loop on DataRow, with embed loop on columns
            //if (dt != null)
                for(int j=0; j<gv.RowCount;j++)
                {
                    extraHeight = mp.BeginPrintUnit(yPos, h);  //Space required for header text
                    xPos = x;
                    for (int i = 0; i < gv.Columns.Count; i++)
                    {
                        if(gv.Columns[i].VisibleIndex<0) continue;
                        string caption = gv.GetRowCellValue(j, gv.Columns[i]).ToString();
                        w = gv.Columns[i].Width;
                        if (xPos+w > x + c.Width)
                            w = x + c.Width - xPos;
                        if (xPos < x + c.Width)
                            mp.DrawString(caption, printFont, _Brush, xPos, yPos, w, h);
                        xPos += w;
                    };
                    mp.EndPrintUnit();
                    yPos += h + extraHeight;
                }

            // Draw horizontal line at the bottom of DataGrid
            if (yPos < y + c.Height + extraHeightHeaderLine)
                yPos = y + c.Height + extraHeightHeaderLine;
            mp.BeginPrintUnit(yPos, 1);
            mp.DrawLines(_Pen, x, yPos, x+c.Width, yPos);
            mp.EndPrintUnit();

            // Finally, Compute extendedHeight
            if ((yPos - y) > c.Height)
                extendedHeight = (yPos - y) - c.Height;
        }