---
title: "C# winform Printing Multipage Margin not set"  
description: "C# winform Printing Multipage Margin not set"  
author: "Tech Sys"  
published: 2014-10-16  
updated: 2014-11-03  
canonical: https://www.mindstick.com/forum/2389/c-sharp-winform-printing-multipage-margin-not-set  
category: "c#"  
tags: ["c#"]  
reading_time: 5 minutes  

---

# C# winform Printing Multipage Margin not set

Hi,\
[iam](https://answers.mindstick.com/blog/40/iam-identity-and-access-management-a-complete-guide) using below [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) for [printing](https://www.mindstick.com/blog/63804/5-ways-you-can-use-printing-in-your-marketing-strategy) ,plz see in the attached [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character),there is 3 pages .1st [page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-page) is ok2 page should be [print](https://www.mindstick.com/blog/301752/types-of-3d-printing-technology) only names without any [header](https://www.mindstick.com/articles/336036/explain-about-html-header-body-and-footer-tags) top [margin](https://answers.mindstick.com/qa/104990/what-is-a-margin-call) is 100also 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();            }        }
```

![C# winform Printing Multipage Margin not set](https://www.mindstick.com/mindstickforums/e59f54c8-e927-430e-b48d-32778d58c339/images/c095f241-e106-42a2-9553-a5f8d2cb4ceb.png)\
\
Please could anybody solve this problem,this is urgent\
rgdsDeziner2000

## Replies

### Reply by Tech Sys

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

### Reply by Tech Sys

please see above my code.

### Reply by John Smith

Paste your updated complete code ...

### Reply by Tech Sys

hi,this is too much delay,solve and finsh my problem friends.still pending my application.

### Reply by Tech Sys

thanks kamlakar Singh,i used code above given but complier error shown like below1.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.\
\
\

### Reply by Anonymous User

Hi Tech Systry 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();        }
```

### Reply by Tech Sys

hi,nobody dont have any solution.this is too much late.

### Reply by Tech Sys

could anybody solve this


---

Original Source: https://www.mindstick.com/forum/2389/c-sharp-winform-printing-multipage-margin-not-set

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
