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?
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?