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