Avatar of Kevin Terry
Kevin Terry
Flag for United States of America asked on

BLURRY TEXT - WINDOW FORMS - PANEL - VB.net

I know this topic has MANY questions/answers but I am still drawing blanks. Running Windows 10, Visual Studio 2019. I have created a Windows Forms App (.NET Framework). Target is .NET Framework 4.7.2. I have a Form created with a Panel on the form. The Panel is sized to 384x576 which is approximate 4" x 6". That is the exact size I have my page size set to. When I print preview (via code) it looks clear, but when it prints to my laser printer, some of the text is blurred. The text is a Label. My apologies up front, almost 80% of the code has been pieced together from "MANY" websites, so if you see any specific part of my code that looks like your code, sorry I am not giving proper credits in the footnotes.

Here is some of my code:

PRINT BUTTON code:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
   Dim myprintdialog As New PrintDialog memoryimage = New System.Drawing.Bitmap(Panel1.Width, Panel1.Height)
   Panel1.DrawToBitmap(memoryimage, Panel1.ClientRectangle)

       If myprintdialog.ShowDialog = DialogResult.OK Then
           Dim value As System.Drawing.Printing.PrinterSettings
           value = myprintdialog.PrinterSettings
           myprintdialog.Document = PrintDocument1
           PrintDocument1.PrintController = New StandardPrintController()
           Panel1.BackColor = Color.White
           PrintDocument1.Print()
       End If
End Sub

Private Sub PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles
     PrintDocument1.PrintPage
    e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality
    e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
    e.Graphics.DrawImage(memoryimage, 0, 0)
End Sub


and added an app.manifest

   <?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
  <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
    <requestedExecutionLevel level="asInvoker" uiAccess="false" />
  </requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
</application>
</compatibility>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
  <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>

Visual Basic.NET

Avatar of undefined
Last Comment
Kevin Terry

8/22/2022 - Mon
Dr. Klahn

It's entirely possible for a window's contents to look great in Print Preview, but that's not what the printer actually gets from Windows when Print is clicked.  Print Preview shows what an ideal printer would do if it was fed that page with perfect resolution -- not what it will look like on the paper.

384x576 is very low resolution when printers normally have resolutions of 400 to 1200 DPI.  In order to blow up that low resolution text to a size where it can be printed, it is being aliased and anti-aliased without mercy by Windows.

What you can do about it:  Try different printface sizes, perhaps?
ASKER CERTIFIED SOLUTION
Kevin Terry

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Kevin Terry

ASKER
I had a suspicion that it was resolution. I have 2 large monitors and used a ruler to measure the 4x6 panel that is on my form. VERY VERY close to 4x6. I have my printer paper size set to 4x6. I'm not understanding why Windows is having to blow something up? Would it be better for me to create a panel twice the size and let Windows scale it down?
Kevin Terry

ASKER
My computer monitor resolution is set to 1920x1080. My printer is a Brother Laser HL-L2325DW and its resolution is 600 x 600 dpi, HQ1200 (2400 x 600 dpi) quality, 1200 x 1200 dpi. It is the 4x6 winform panel i'm trying to print on a 4x6 piece of paper. Is this not a 1:1 ratio? If anything i would think windows would be scaling down to the printer. 
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy