We help IT Professionals succeed at work.
Get Started

Print Document - Change Margins

freezingHot
freezingHot asked
on
7,283 Views
Last Modified: 2009-01-05
good day.

i am having trouble defining the margins when printing a document.

the text is printing down the middle of the page.  i want the left hand margin to be nominal.  my setting below is .10"; however, it isn't working.

any help would be appreciated.

thanks.

        void pd_PrintPage(object sender, PrintPageEventArgs e)
        {
            int charactersOnPage = 0;
            int linesPerPage = 0;
            e.PageSettings.Margins.Left = 10;
            e.PageSettings.Margins.Right = 25;
            e.PageSettings.Landscape = false;

            // Sets the value of charactersOnPage to the number of characters
            // of stringToPrint that will fit within the bounds of the page.
            Font ft = new Font(FontFamily.GenericMonospace, 8);
            e.Graphics.MeasureString(pickList, ft,
                e.MarginBounds.Size, StringFormat.GenericTypographic,
                out charactersOnPage, out linesPerPage);

            // Draws the string within the bounds of the page
            e.Graphics.DrawString(pickList, ft, Brushes.Black,
                e.MarginBounds, StringFormat.GenericTypographic);

            // Remove the portion of the string that has been printed.
            pickList = pickList.Substring(charactersOnPage);

            // Check to see if more pages are to be printed.
            e.HasMorePages = (pickList.Length > 0);
        }
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE