Home > DeveloperSection > Forums > C# winform Printing Multipage Margin not set
Tech Sys
Tech Sys

Total Post:15

Points:105
Posted on    October-16-2014 12:35 AM

 C# C# 
Ratings:


 8 Reply(s)
 1022  View(s)
Rate this:
Hi,

iam using below code for printing ,plz see in the attached image,there is 3 pages .
1st page is ok
2 page should be print only names without any header top margin is 100
also same as 3rd page.

here is my code

 string strDisplay = "Students Details";
                System.Drawing.Font fntString = new Font("Times New Roman", 28, FontStyle.Bold);
                e.Graphics.DrawString(strDisplay, fntString, Brushes.Black, 250, 100);
                e.Graphics.DrawLine(new Pen(Color.Black, 1), 60, 184, 700, 184);
                e.Graphics.DrawLine(new Pen(Color.Black, 1), 60, 188, 700, 188);
                string strDisplay1 = "Company name :";
                System.Drawing.Font fntString1 = new Font("Times New Roman", 16, FontStyle.Bold);
                e.Graphics.DrawString(strDisplay1, fntString1, Brushes.Black, 100, 200);
                string strDisplay2 = "Address :";
                System.Drawing.Font fntString2 = new Font("Times New Roman", 16, FontStyle.Bold);
                e.Graphics.DrawString(strDisplay2, fntString2, Brushes.Black, 100, 250);
                string strDisplay3 = "City :";
                System.Drawing.Font fntString3 = new Font("Times New Roman", 16, FontStyle.Bold);
                e.Graphics.DrawString(strDisplay3, fntString3, Brushes.Black, 100, 300);

                e.Graphics.DrawLine(new Pen(Color.Black, 1), 60, 350, 700, 350);

               
                System.Drawing.Font fntString4 = new Font("Times New Roman", 16, FontStyle.Bold);
                e.Graphics.DrawString("Student Name"+"\n"+"--------------------", fntString4, Brushes.Black, 100, 400);
           
            

                float linesPerPage = 0;
                float yPosition = 450;
                int count = 0;
                float leftMargin = 100;
                float topMargin = 450;
                string line = null;

                Font printFont = new System.Drawing.Font("Times New Roman", 8, FontStyle.Regular);
                SolidBrush myBrush = new SolidBrush(Color.Black);



                linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics);
                while (count < linesPerPage && ((line = myReader.ReadLine()) != null))
                {
                    yPosition = topMargin + (count * printFont.GetHeight(e.Graphics));
                    e.Graphics.DrawString(line, printFont, myBrush, leftMargin, yPosition, new StringFormat());
                    count++;
                }

                if (line != null)
                {
                    e.HasMorePages = true;
                }
                else
                {
                    e.HasMorePages = false;
                }
                myBrush.Dispose();
            }
        }



Please could anybody solve this problem,this is urgent

rgds
Deziner2000


Tech Sys
Tech Sys

Total Post:15

Points:105
Posted on    October-16-2014 10:55 PM

could anybody solve this

Tech Sys
Tech Sys

Total Post:15

Points:105
Posted on    October-28-2014 10:55 PM

hi,
nobody dont have any solution.this is too much late.

Modified On Oct-28-2014 10:56:01 PM

Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    October-29-2014 12:08 AM

Hi Tech Sys
try this:

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)

        {

            Font font1 = new Font("Arial", 10, FontStyle.Regular);

            int charactersOnPage = 0;

            int linesPerPage = 0;

            e.Graphics.MeasureString(stringToPrint, font1,

                e.MarginBounds.Size, StringFormat.GenericTypographic,

                out charactersOnPage, out linesPerPage);

            e.Graphics.DrawString(stringToPrint, font1, Brushes.Black,

                e.MarginBounds, StringFormat.GenericTypographic);

            stringToPrint = stringToPrint.Substring(charactersOnPage);

            e.HasMorePages = (stringToPrint.Length > 0);

        }

this is the print button:

private void PrintButton_Click(object sender, EventArgs e)

        {

            stringToPrint = tabsProperties[tabsProperties.IndexOf(new TabProperties(this.tabControl1.SelectedIndex))].TabHtml;

            printDialog1.ShowDialog();

            printDocument1.Print();

        }


Tech Sys
Tech Sys

Total Post:15

Points:105
Posted on    October-29-2014 3:35 AM

thanks kamlakar Singh,
i used code above given but complier error shown like below
1.Error 4 'notepad_demo.Form1' does not contain a definition for 'tabControl1' and no extension method 'tabControl1' accepting a first argument of type 'notepad_demo.Form1' could be found (are you missing a using directive or an assembly reference?)

2 Error 1 The name 'tabsProperties' does not exist in the current context

3.Error 3 The type or namespace name 'TabProperties' could not be found (are you missing a using directive or an assembly reference?)

advice me please.




Tech Sys
Tech Sys

Total Post:15

Points:105
Posted on    October-31-2014 7:01 AM

hi,
this is too much delay,solve and finsh my problem friends.still pending my application.

John Smith

Total Post:102

Points:720
Posted on    October-31-2014 12:24 PM

Paste your updated complete code ...

Tech Sys
Tech Sys

Total Post:15

Points:105
Posted on    November-02-2014 10:22 PM

please see above my code.

Tech Sys
Tech Sys

Total Post:15

Points:105
Posted on    November-03-2014 9:17 PM

hi,

Plz check my above code and solve and finish this topic as soon.anybody solve what i need and ref aboce code and correct it.please.
stil stop my application due to this problem.

thanks

Don't want to miss updates? Please click the below button!

Follow MindStick