C# WINFORM PRINTING MULTIPAGE MARGIN NOT SET

Tech Sys

Total Post:15

Points:105
Posted by  Tech Sys
C# 
C#
 1379  View(s)
Ratings:
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
  1. Tech Sys

    Post:15

    Points:105
    Re: C# winform Printing Multipage Margin not set

    could anybody solve this

  1. Tech Sys

    Post:15

    Points:105
    Re: C# winform Printing Multipage Margin not set

    hi,

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

      Modified On Oct-28-2014 10:56:01 PM
  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: C# winform Printing Multipage Margin not set

    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();

            }

  1. Tech Sys

    Post:15

    Points:105
    Re: C# winform Printing Multipage Margin not set

    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.



  1. Tech Sys

    Post:15

    Points:105
    Re: C# winform Printing Multipage Margin not set

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

  1. John Smith

    Post:103

    Points:727
    Re: C# winform Printing Multipage Margin not set

    Paste your updated complete code ...

  1. Tech Sys

    Post:15

    Points:105
    Re: C# winform Printing Multipage Margin not set

    please see above my code.

  1. Tech Sys

    Post:15

    Points:105
    Re: C# winform Printing Multipage Margin not set

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!