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 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.º 3
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.º 4
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);
        }
        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);
                }
        }