Windows Develop Bookmark and Share   
 index > Windows Forms General > TextRenderer.DrawText giving me very tiny print
 

TextRenderer.DrawText giving me very tiny print

I have heard there are problems with Graphics.DrawString, so I was going to use TextRenderer.DrawText

The problem is, no matter what I set my Font size too, the print that comes out is very tiny.

private static void MyPrintDocument_PrintPage(object sender, PrintPageEventArgs ParmPrintPageEventArgs) {
            Font MyFont = new Font("Arial", 20F, FontStyle.Bold, GraphicsUnit.Pixel);
            StringFormat MyStringFormat = new StringFormat();
            MyStringFormat.FormatFlags = StringFormatFlags.DirectionVertical;

            ParmPrintPageEventArgs.Graphics.DrawString("Hello", MyFont , Brushes.Black, 100, 100, MyStringFormat);
            //ParmPrintPageEventArgs.Graphics.DrawString("Hello", Font("Arial", 32), Brushes.Black, 100, 100);

            TextRenderer.DrawText(ParmPrintPageEventArgs.Graphics, "Visual Studio", MyFont, new Point(10, 10), Color.Black);
        }
JimGuyer  Tuesday, September 22, 2009 6:27 PM
You must use Graphics.DrawString() in the PrintPage event handler. The problems it has are not an issue, printers have very good resolution (600 dpi).

Hans Passant.
  • Marked As Answer byJimGuyer Tuesday, September 22, 2009 6:54 PM
  •  
nobugz  Tuesday, September 22, 2009 6:40 PM
I believe the problem is specifically due to using GraphicsUnit .Pixel instead of GraphicsUnit.Point.

In this case, when you print, you're pixels are tiny (often 1/600th or 1/1200th of an inch), so your text is being drawn microscopically. If you specify the font in terms of points (1/72 inch), it should look more reasonable.

However, Hans is correct - there really is no problem with using Graphics.DrawString() with printing, since the resolution is so high on printers. This will look perfect.

Reed Copsey, Jr. - http://reedcopsey.com
  • Marked As Answer byJimGuyer Tuesday, September 22, 2009 6:54 PM
  •  
Reed Copsey, Jr.  Tuesday, September 22, 2009 6:43 PM
You must use Graphics.DrawString() in the PrintPage event handler. The problems it has are not an issue, printers have very good resolution (600 dpi).

Hans Passant.
  • Marked As Answer byJimGuyer Tuesday, September 22, 2009 6:54 PM
  •  
nobugz  Tuesday, September 22, 2009 6:40 PM
I believe the problem is specifically due to using GraphicsUnit .Pixel instead of GraphicsUnit.Point.

In this case, when you print, you're pixels are tiny (often 1/600th or 1/1200th of an inch), so your text is being drawn microscopically. If you specify the font in terms of points (1/72 inch), it should look more reasonable.

However, Hans is correct - there really is no problem with using Graphics.DrawString() with printing, since the resolution is so high on printers. This will look perfect.

Reed Copsey, Jr. - http://reedcopsey.com
  • Marked As Answer byJimGuyer Tuesday, September 22, 2009 6:54 PM
  •  
Reed Copsey, Jr.  Tuesday, September 22, 2009 6:43 PM
Thanks. I will use DrawString.

Just for fun, I tried GraphicsUnits. Intllisense lists: (Display, Document, Inch, Millimeter, Pixel, Point, World) as options.

I used point and changed the sizeto 200F. The resulting print was about 1 inch high for TextRender, and about 3 inches high for DrawString


Thanks again

        private static void MyPrintDocument_PrintPage(object sender, PrintPageEventArgs ParmPrintPageEventArgs) {
            Font MyFont = new Font("Arial", 200F, FontStyle.Bold, GraphicsUnit.Point);
            StringFormat MyStringFormat = new StringFormat();
            MyStringFormat.FormatFlags = StringFormatFlags.DirectionVertical;

            ParmPrintPageEventArgs.Graphics.DrawString("Hello", MyFont , Brushes.Black, 100, 100, MyStringFormat);
            //ParmPrintPageEventArgs.Graphics.DrawString("Hello", Font("Arial", 32), Brushes.Black, 100, 100);

            TextRenderer.DrawText(ParmPrintPageEventArgs.Graphics, "Visual Studio", MyFont, new Point(10, 10), Color.Black);
        }
JimGuyer  Tuesday, September 22, 2009 6:53 PM
Leave the GraphicsUnit alone. By default it's GraphicsUnit.Display which is 1/100 inch. Learn to live with it. You'll find printing bugs if you don't.
JohnWein  Tuesday, September 22, 2009 9:55 PM

You can use google to search for other answers

Custom Search

More Threads

• Point on PictureBox on Panel
• C# convert ppt file into movi/vedio file
• VB .NET: How to display "Licenced to: user name"
• Changing Font in CR with a Font Embedded within my assembly
• Access to stuff in another form.
• Performing other task while for-loop is underway....
• using IndexOf()
• Accessing to a menuitem on parentform from a childform in C#
• PropertyGrid Reset context menu
• Progerss bar