Printing on a pre-printed form with VB.NET

G

Guest

Hello Everyone,

I need to print on pre-printed form from my VB.NET app. The form I am
printing on has about 200 fields and each field needs to be justified
seperately. CR for .Net isn't giving me accurate output. The CR is close,
but a little off here and there and adjustments haven't worked.
When using the Drawstring Method it takes x and y coordinates for the upper
left hand corner as a 'single' datatype. Does anyone know how that datatype
converts to millimeters?

Thanks.
 
R

Ron Allen

Chris,
The 'standard' (World) unit of measure for DrawString, etc is 1/100ths
of an inch. You should be able to set the drawing unit to millimeters using
the PageUnit member of the Graphics used.

Also when drawing with the Graphics object onto a printer you need to
accomodate the printer's 'hard' margins. For FW2.0 there will be some
automatic things for this but for now you will need to PInvoke GetDeviceCaps
to get the actual margins to offset your drawing by. You can search for
'hard margins' in microsoft.public.dotnet.framework.drawing for discussion
on these issues. If you like I can send you a small C# library routine I
wrote to get these items or look in the microsoft.public.dotnet.languages.vb
group for a translation that H. Wagner wrote on this.

Ron Allen
 
G

Guest

Ron,

Thanks so much, the page unit is exactly what I was looking for. Also, if
you could post the library routine for discovering the printer's hard margins
that woud be great. I tried searching the newsgroups you listed for the vb
translation however was unable to find it.

Thanks
Chris
 
R

Ron Allen

OK, here is the version that Herfried Wagner posted. Note that this returns
hard margins in 1/100ths of an inch so modify as desired to get your
measurement units.

Before calling this use GetHdc() and ReleaseHdc() on the Graphics to get the
device contect to use for the call. I just get and release immediately
before calling GetHardMargins.

BTW you need to search microsoft.public.dotnet.languages.vb to find this.

Ron Allen

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



Chris said:
Ron,

Thanks so much, the page unit is exactly what I was looking for. Also, if
you could post the library routine for discovering the printer's hard
margins
that woud be great. I tried searching the newsgroups you listed for the
vb
translation however was unable to find it.

Thanks
Chris
-----snip---------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top