printing stuff

nsmoller
09-08-2003, 09:04 AM
i also have a technical question regarding printing stuff :)

i want to print a whole page of stuff... is there an add on/component i should be using, or just make a 8.5 x 11 " rich text box on a form and dump line by line what i want in there?

also if i do that, how do i zoom in/out like in a print preview window...

am i on or off point with my thoughts???

BlueDragon
09-08-2003, 09:07 AM
Printer.Print and Printer.EndDoc should get you started. If your printing items in a list, you need a For...Next loop, not sure if your printing a list or a full page, but that should get you started.

nsmoller
09-08-2003, 09:09 AM
i understand how to print, but how to take an input form and make like an invoice sheet/etc... is this all done by hand into a rich text box???

SpaceFrog
09-08-2003, 09:13 AM
Take a look at printer.currentx and .currenty they will allow you to position elements as you compose your page...

You can actually print out of a rtb but it takes a bit of code :


Option Explicit

Private Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Type CharRange
cpMin As Long ' First character of range (0 for start of doc)
cpMax As Long ' Last character of range (-1 for end of doc)
End Type

Private Type FormatRange
hdc As Long ' Actual DC to draw on
hdcTarget As Long ' Target DC for determining text formatting
rc As Rect ' Region of the DC to draw to (in twips)
rcPage As Rect ' Region of the entire DC (page size) (in twips)
chrg As CharRange ' Range of text to draw (see above declaration)
End Type

Private Const WM_USER As Long = &H400
Private Const EM_FORMATRANGE As Long = WM_USER + 57
Private Const EM_SETTARGETDEVICE As Long = WM_USER + 72
Private Const PHYSICALOFFSETX As Long = 112
Private Const PHYSICALOFFSETY As Long = 113

Private Declare Function GetDeviceCaps Lib "gdi32" ( _
ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal msg As Long, ByVal wp As Long, _
lp As Any) As Long
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" _
(ByVal lpDriverName As String, ByVal lpDeviceName As String, _
ByVal lpOutput As Long, ByVal lpInitData As Long) As Long


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''
' LeftMarginWidth - Width of desired left margin in twips
'
' TopMarginHeight - Height of desired top margin in twips
'
' RightMarginWidth - Width of desired right margin in twips
'
' BottomMarginHeight - Height of desired bottom margin in twips
'
' Notes - If you are also using WYSIWYG_RTF() on the provided RTF
' parameter you should specify the same LeftMarginWidth and
' RightMarginWidth that you used to call WYSIWYG_RTF()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''

Public Sub PrintRTF(RTF As RichTextBox, LeftMarginWidth As Long, _
TopMarginHeight, RightMarginWidth, BottomMarginHeight)
Dim LeftOffset As Long, TopOffset As Long
Dim LeftMargin As Long, TopMargin As Long
Dim RightMargin As Long, BottomMargin As Long
Dim fr As FormatRange
Dim rcDrawTo As Rect
Dim rcPage As Rect
Dim TextLength As Long
Dim NextCharPosition As Long
Dim r As Long

' Start a print job to get a valid Printer.hDC
Printer.Print Space(1)
Printer.ScaleMode = vbTwips

' Get the offsett to the printable area on the page in twips
LeftOffset = Printer.ScaleX(GetDeviceCaps(Printer.hdc, _
PHYSICALOFFSETX), vbPixels, vbTwips)
TopOffset = Printer.ScaleY(GetDeviceCaps(Printer.hdc, _
PHYSICALOFFSETY), vbPixels, vbTwips)

' Calculate the Left, Top, Right, and Bottom margins
LeftMargin = LeftMarginWidth - LeftOffset
TopMargin = TopMarginHeight - TopOffset
RightMargin = (Printer.Width - RightMarginWidth) - LeftOffset
BottomMargin = (Printer.Height - BottomMarginHeight) - TopOffset

' Set printable area rect
rcPage.Left = 0
rcPage.Top = 0
rcPage.Right = Printer.ScaleWidth
rcPage.Bottom = Printer.ScaleHeight

' Set rect in which to print (relative to printable area)
rcDrawTo.Left = LeftMargin
rcDrawTo.Top = TopMargin
rcDrawTo.Right = RightMargin
rcDrawTo.Bottom = BottomMargin

' Set up the print instructions
fr.hdc = Printer.hdc ' Use the same DC for measuring and rendering
fr.hdcTarget = Printer.hdc ' Point at printer hDC
fr.rc = rcDrawTo ' Indicate the area on page to draw to
fr.rcPage = rcPage ' Indicate entire size of page
fr.chrg.cpMin = 0 ' Indicate start of text through
fr.chrg.cpMax = -1 ' end of the text

' Get length of text in RTF
TextLength = Len(RTF.Text)

' Loop printing each page until done
Do
' Print the page by sending EM_FORMATRANGE message
NextCharPosition = SendMessage(RTF.hWnd, EM_FORMATRANGE, True, fr)
If NextCharPosition >= TextLength Then Exit Do 'If done then exit
fr.chrg.cpMin = NextCharPosition ' Starting position for next page
Printer.NewPage ' Move on to next page
Loop

' Commit the print job
Printer.EndDoc

' Allow the RTF to free up memory
r = SendMessage(RTF.hWnd, EM_FORMATRANGE, False, ByVal CLng(0))
End Sub

nsmoller
09-08-2003, 09:17 AM
that is WAY over my head i think.... any dummy guides to this stuff?

nsmoller
09-08-2003, 10:52 AM
ok i'm understanding this more and more...

u can use a picture box and put anything anywhere (based on currentx and currenty)

do i really need to have a picture box or can it be a memory resident thing?
do i need to dimension it to 8.5 x 11???

Cags
09-08-2003, 11:24 AM
If all you want todo is print to the printer you don't need a picturebox, as you can use the Printer methods CurrentX and CurrentY.

Printer.CurrentX = integer
Printer.CurrentY = integer

the only thing you have to worry about then is the scaling. You can use scaleleft and scalewidth etc to sort this.

nsmoller
09-08-2003, 11:41 AM
right but if i'm doing a print preview type deal i would

Cags
09-08-2003, 01:07 PM
Yes, well from what i understand you could use anything with a hdc, but i'm not sure, it would probably be best with the picture box.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum