• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 482
  • Last Modified:

Screen to print problem


I'm trying to build a simple report generator

the user can drag textboxes on to a panel and type a text (he is able to change the font)

now I want the print to look exactly like on screen, that is where my problem is, how do I that ?

I got everything working except that it doesn't look exactly as on screen, it seems the font part doesn't work the same on screen as it does on print

If you need additional information, ask :-)

RB
0
RonaldBiemans
Asked:
RonaldBiemans
  • 7
  • 6
  • 2
1 Solution
 
g_johnsonCommented:
For starters, I believe the printer's font must be set in code to match the font on the form.  Try using "Courier New" for example, for both the textbox and at the printer, and see if that works.
0
 
g_johnsonCommented:
btw, if this works, you can develop code to set the printer's font "conditionally" based on what the user is doing
0
 
RonaldBiemansAuthor Commented:
No that is not the problem the fonts ARE set the same.

but somehow the don't seem the be the same length to explain

If I check the font and the size on the form with the word "HALLO" in the textbox

like

        Dim g As Graphics
        g = Panel2.CreateGraphics
         MsgBox(g.MeasureString(sender.text, sender.font).Width & "-" & sender.font.name & "-" & sender.font.sizeinpoints)

I get 48,24 - Microsoft Sans Serif - 7,8

if I do the same in the PrintPage event

I get 40,20 - Microsoft Sans Serif - 7,8

So it probably has something to do with dpi I just don't know how to correct it

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Bob LearnedCommented:
Does the font return the same size in points in the different contexts?

Bob
0
 
RonaldBiemansAuthor Commented:
Hi bob,

no they both return 7.8

      
If I check the font and the size on the form with the word "HALLO" in the textbox

like

        Dim g As Graphics
        g = Panel2.CreateGraphics
         MsgBox(g.MeasureString(sender.text, sender.font).Width & "-" & sender.font.name & "-" & sender.font.sizeinpoints)

I get 48,24 - Microsoft Sans Serif - 7,8

if I do the same in the PrintPage event

I get 40,20 - Microsoft Sans Serif - 7,8

0
 
RonaldBiemansAuthor Commented:
ROFL, It had nothing to do with my programming, the DPI setting of the screen was the culprit, it is set to increased font size (120 instead of 96) when I set it to 96 then everything is OK
0
 
Bob LearnedCommented:
Large fonts are the bane of my existence :(

Bob
0
 
RonaldBiemansAuthor Commented:
LoL, indeed, and probably the only way to detect this is with WMI, or do you have a very cunning alternative.
0
 
Bob LearnedCommented:
Ronald,

As the "WMI" guy, still learning, how do you get this with WMI?  I know that you can get a lot of information from the SystemParametersInfo API call, but I am not sure if that information is there?

Bob
0
 
RonaldBiemansAuthor Commented:
Hmm, don't even need WMI, I can just check the DPIX/Y setting of the form graphics object, why couldn't I find these things 3 days ago, ROFL
0
 
Bob LearnedCommented:
Ok, there's your magic that I didn't know, since I don't mess with those kinds of things any more.  I kill anyone around here who sets large fonts on me, and then I don't have to worry about them anymore.  

I am always willing to learn something new.  How did you manage that?

Bob
0
 
RonaldBiemansAuthor Commented:
I think I'm going adopt your killing suggestion, it will save me a lot of work.

regarding the DPI setting its as simple as

Dim g As Graphics
g = Panel2.CreateGraphics
select case G.DpiX
case 96 'Normal
case 120 ' Large
case else ' custom
end select

0
 
Bob LearnedCommented:
Thanks Ronald.  Another one for the bookmarks.

Bob
0
 
Bob LearnedCommented:
Here is the resulting class that will help others, if they ask:

Public Class SystemFont

  Public Enum FontSizeType
    Large
    Small
    Custom
  End Enum  'FontSizeType

  ''' -----------------------------------------------------------------------------
  ''' <summary>
  ''' Get the system font size, by using a temporary form's Graphics
  ''' object to query the DPI setting.
  ''' </summary>
  ''' <value>The font size as an enum (Large, Small, Custom)</value>
  ''' -----------------------------------------------------------------------------
  Public Shared ReadOnly Property FontSize() As FontSizeType
    Get
      ' Create a temporary form to test the system font DPI
      Dim frm As New Form
      Dim gr As Graphics = frm.CreateGraphics()

      ' Get the DPI from the form's Graphics object.
      Dim dpiX As Integer = gr.DpiX

      ' Dispose of the temporary objects.
      gr.Dispose()
      frm.Dispose()

      ' Test the DPI to return an enum.
      Select Case dpiX
        Case 96
          Return FontSizeType.Small
        Case 120
          Return FontSizeType.Large
        Case Else
          Return FontSizeType.Custom
      End Select       'dpiX
    End Get
  End Property  'DPI

End Class

Bob
0
 
RonaldBiemansAuthor Commented:
Bob, you are as thoughtfull as ever :=)

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now