Accurate print preview?

Sonreir
11-01-2005, 10:28 AM
Hey all,

I'm working on a project right now that requires a user to setup a report and at the same time, I'm dynamically creating a print preview in a picturebox that mimics the changes they make.

My problem is, when the user (myself at this point) goes to set something up against the right margin, it's too far. I think the problem is in my setting up of the preview; it's the incorrect size.

This is the function I've got so far, please help me out if you are able:
Public Function getA4SizeInPx(ByVal g As Graphics, Optional ByVal isPortrait As Boolean = True) As Size
Dim x As Double = g.DpiX
Dim y As Double = g.DpiY

x /= 25.4 'mm per inch
y /= 25.4

If isPortrait Then
x *= 210
y *= 297
Else
x *= 297
y *= 210
End If

x *= Screen.PrimaryScreen.WorkingArea.Width / 1152 'I reckon my problem is here
y *= Screen.PrimaryScreen.WorkingArea.Height / 864

Return New Size(Convert.ToInt32(x), Convert.ToInt32(y))
End Function

I arrived at the 1152 x 864 through trial-and-error, so I assume that is the incorrect portion of my function. Anyone help me out?

Hammer65
11-03-2005, 09:17 AM
I am new to VB.Net so this may not help but here goes:

1152 x 864 looks a lot like a preset Desktop resolution. I would think that you would need to get those values at run time from the system. If the user runs a different resolution than you it will be off, even if you get it working for your current settings.

This is straight from the help files in VB.net Studio 2003
Dim desktopSize As Size
desktopSize = System.Windows.Forms.SystemInformation.PrimaryMonitorSize
Dim height As Integer = desktopSize.Height
Dim width As Integer = desktopSize.Width

Sonreir
11-03-2005, 09:51 AM
Cheers, Hammer. I sorted it out though. Probably not the best way of doing things, but I figured out how many 1 point letter Ms fit across that page and then set my page to that width. :huh:

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum