Thank you.
I was able to scale the document using:
e.Graphics.Scal eTransform(0.95 F, 0.95F)
In order to scale using Transform.Scale method I had to:
Dim myMatrix As New System.Drawing. Drawing2D.Matri x
myMatrix.Scale( 0.95F, 0.95F)
e.Graphics.Tran sform = myMatrix
Is this the correct way of using Transform.Scale or am I missing the concept
somewhere?
Also I would really like to be able to use Mr. Wagners class for getting the
hard margins but keep getting a System.InvalidO perationExcepti on - The
object is currently in use elsewhere and just can't figure it out on my own.
In stepping through the debugger I actually see the
System.InvalidO perationExcepti on error first comming up in the Locals window
on the Graphics object at:
Dim hDC As IntPtr = Graphics.GetHdc ()
hDC is populated (with the printer handle I assume)
But no ErrorException is thrown until m.Left = CInt(ox * 100 /
Graphics.DpiX); then I get the "The object is currently in use elsewhere"
error.
Please help me to understand??!!!
Here is the code:
Imports System.Drawing. Printing
''' <summary>
''' Provides information about a device.
''' </summary>
Public Class Device
Private Declare Function GetDeviceCaps Lib "gdi32.dll" ( _
ByVal hdc As IntPtr, _
ByVal nIndex As Int32 _
) As Int32
Private Const PHYSICALOFFSETX As Int32 = 112 ' In device units.
Private Const PHYSICALOFFSETY As Int32 = 113 ' In device units.
Private Const HORZRES As Int32 = 8 ' In pixels/dots.
Private Const VERTRES As Int32 = 10 ' In pixels/dots.
''' <summary>
''' Gets a device's physical margins.
''' </summary>
''' <param name="Graphics" >The device's <c>Graphics</c> object.</param>
''' <returns>
''' The device's physical margins in 0.001 inch units.
''' </returns>
Public Shared Function GetPhysicalMarg ins( _
ByVal Graphics As Graphics _
) As Margins
Dim hDC As IntPtr
Try
hDC = Graphics.GetHdc () <========== Locals window shows
Graphics as System.InvalidO perationExcepti on, but no error is thrown
Catch ex As InvalidOperatio nException
End Try
Dim m As Margins = GetPhysicalMarg ins(hDC, Graphics)
Graphics.Releas eHdc(hDC)
Return m
End Function
''' <summary>
''' Gets a device's physical margins.
''' </summary>
''' <param name="hDC">Hand le to the device context.</param>
''' <returns>
''' The device's physical margins in 0.001 inch units.
''' </returns>
Public Shared Function GetPhysicalMarg ins( _
ByVal hDC As IntPtr _
) As Margins
Dim g As Graphics = Graphics.FromHd c(hDC)
Dim m As Margins = GetPhysicalMarg ins(hDC, g)
g.Dispose()
Return m
End Function
''' <summary>
''' Gets a device's physical margins.
''' </summary>
''' <param name="hDC">Hand le to the device context.</param>
''' <param name="Graphics" >The device's <c>Graphics</c> object.</param>
''' <returns>
''' The device's physical margins in 0.001 inch units.
''' </returns>
Private Shared Function GetPhysicalMarg ins( _
ByVal hDC As IntPtr, _
ByVal Graphics As Graphics _
) As Margins
Dim m As New Margins
Dim ox As Int32 = GetDeviceCaps(h DC, PHYSICALOFFSETX )
Dim oy As Int32 = GetDeviceCaps(h DC, PHYSICALOFFSETY )
With m
.Left = CInt(ox * 100 / Graphics.DpiX) <==========
System.InvalidO perationExcepti on - The object is currently in use
elsewhere - ERROR IS THROWN HERE
.Top = CInt(oy * 100 / Graphics.DpiY)
.Right = _
CInt( _
(ox + GetDeviceCaps(h DC, HORZRES)) * 100 / _
Graphics.DpiX _
)
.Bottom = _
CInt( _
(oy + GetDeviceCaps(h DC, VERTRES)) * 100 / _
Graphics.DpiY _
)
End With
Return m
End Function
End Class
Public Class Form1
Inherits System.Windows. Forms.Form
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim p As New PrinterSettings
For Each PrinterName As String In PrinterSettings .InstalledPrint ers
p.PrinterName = PrinterName
Dim g As Graphics = p.CreateMeasure mentGraphics()
MsgBox( _
PrinterName & ControlChars.Ne wLine & _
Device.GetPhysi calMargins(g).T oString() & "[0.01 inch]" _
)
g.Dispose()
Next PrinterName
End Sub
End Class
"Ron Allen" <rallen@_nospam _src-us.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Just call the Graphics.Transf orm.Scale method on the Graphics being
used and specify the x and y scaling factors and everything will be done
for you as far as shrinking the document.
Ron Allen
"DazedAndConfus ed" <Ac********@yah oo.com> wrote in message
news:eU******** ******@tk2msftn gp13.phx.gbl... Is there a way to scale programmaticall y? A way to specify that the
document should print 95% of size. Or do you have to code alternate font
sizes, x, y, etc.?
Any good examples you can poit me to?
"Ron Allen" <rallen@_nospam _src-us.com> wrote in message
news:uZ******** ******@TK2MSFTN GP12.phx.gbl... This sounds like you have hit the 'hard margins' on the printer.
Most printers won't print over a whole page. Some older ink jets have
wide margin areas.
You can PInvoke GetDeviceCaps to find out the actual
horizontal/vertical hard margins on the printer. You could then scale
your print area to fit all your printed items within the actual display
area of the printer. If you search for GetHardMargins you should find
some code to get printer margins that Mr. Wagner converted to VB.
In framework 2.0 you can get this information without calling
GetDeviceCaps and use that to compensate.
Ron Allen
"DazedAndConfus ed" <Ac********@yah oo.com> wrote in message
news:Os******** ******@TK2MSFTN GP14.phx.gbl...
I have a 8.5 x 11 landscape document with about 1/4 inch of space on the
left and right where there is no print.
The document displays perfect in print preview, but when I print it,
about 1/2 inch on the right is not printed (leaving about 3/4 inch
empty margin on the right side of the page). The left side starts about
1/4 inch in and prints just like I expect it to.
I tried setting the margins to 0 and OriginAtMargins = True. The print
began about an 1/8" at the left but still stoped about 3/4" on the
right.
I know I can change the document so that there is no print for the last
3/4 inch on the right, but that seems like coding around the problem
instead of getting it right.
Is there anything I can do besides coding the width of the report
shorter?