Having some major problems with printing

  • Thread starter Thread starter Danielle Robinson
  • Start date Start date
D

Danielle Robinson

Hi,
I am fairly new to vb.net and over the past few weeks I have been
working on printing text. But it would seem that this is not my strong point
because nothing works. I have had multiple problems and most of them have
been because of margins.

Firstly neither the printing code nor my printer seem to recognise the
margins of 100 that I set. On my printer the heading which is at x-position
0 prints out about 2 1/2 cm down the page but on another printer it prints
out right at the top. The same happens with my left margin. No matter what
number I put into the left margin be it 1 or 100, it just wont print there.
On my printer there is about one cm space and on another it is right at the
edge...again :(
I used
Private mymargins As New System.Drawing.Printing.Margins(100, 100, 100, 100)

I also added
pd.OriginAtMargins =True
e.PageBounds.FromLTRB(100, 100, 700, 700)

Nothing woks.
My other problems are related to my margin problem so I figured I should get
the main one out of the way first.
I really need some help with this because I am really struggling.

Thankyou so much in advance,
Danielle.
 
Danielle Robinson said:
because nothing works. I have had multiple problems and most of them have
been because of margins.

Firstly neither the printing code nor my printer seem to recognise the
margins of 100 that I set. On my printer the heading which is at x-position
0 prints out about 2 1/2 cm down the page but on another printer it prints
out right at the top. The same happens with my left margin. No matter what
number I put into the left margin be it 1 or 100, it just wont print there.
On my printer there is about one cm space and on another it is right at the
edge...again :(
I used

You may want to obtain physical margins:

(untested, sample based on a C# sample by Ron Allen)

<cite>
Get the hDc from the printer Graphics object during the print call. The
reason I suggest this is that the printer driver for the selected
printer may have a margin that is different from the PrintPreviewDialog
margin.
</cite>

\\\
Public Declare Function GetDeviceCaps Lib "gdi32.dll" ( _
ByVal hDc As IntPtr, _
ByVal funct As Int32 _
) As Int32

Private Const PHYSICALOFFSETX As Int32 = 112
Private Const PHYSICALOFFSETY As Int32 = 113
Private Const HORZRES As Int32 = 8
Private Const VERTRES As Int32 = 10
Private Const HORZSIZE As Int32 = 4
Private Const VERTSIZE As Int32 = 6

Public Sub GetHardMargins( _
ByVal hDC As IntPtr, _
ByRef Left As Single, _
ByRef Top As Single, _
ByRef Right As Single, _
ByRef Bottom As Single _
)
Dim offx As Single = _
Convert.ToSingle(GetDeviceCaps(hDC, PHYSICALOFFSETX))
Dim offy As Single = _
Convert.ToSingle(GetDeviceCaps(hDC, PHYSICALOFFSETY))
Dim resx As Single = _
Convert.ToSingle(GetDeviceCaps(hDC, HORZRES))
Dim resy As Single = _
Convert.ToSingle(GetDeviceCaps(hDC, VERTRES))
Dim hsz As Single = _
Convert.ToSingle(GetDeviceCaps(hDC, HORZSIZE)) / 25.4F ' Screen width in inches.
Dim vsz As Single = _
Convert.ToSingle(GetDeviceCaps(hDC, VERTSIZE)) / 25.4F ' Screen height in inches.
Dim ppix As Single = resx / hsz
Dim ppiy As Single = resy / vsz
Left = (offx / ppix) * 100.0F
Top = (offy / ppix) * 100.0F
Bottom = Top + (vsz * 100.0F)
Right = Left + (hsz * 100.0F)
End Sub
///
 
Back
Top