|
-
January 1st, 2006, 10:30 PM
#1
Printing a Form in the center of the page
my form dosent fill the screen when i print is there any way to center it this the code i use
Code:
Private Sub Command8_Click()
SaveCurrentRecord
Printer.Orientation = vbPRORLandscape
client.PrintForm
End Sub
-
January 2nd, 2006, 04:25 AM
#2
Re: Printing a Form in the center of the page
Probably you would use some API functions to do this. You might have to use the GetWindowDC to get the Form's windows DC (device context), and then the StretchBlt API to copy/paint and scale the image into the Printer's DC. Here is a sample code...
API function declarations
Code:
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Implemetation
Code:
Dim nActualWidth&
VB.Printer.ScaleMode = vbPixels
nActualWidth = Me.Width \ VB.Printer.TwipsPerPixelX
VB.Printer.Print
StretchBlt VB.Printer.hdc, (VB.Printer.ScaleWidth - nActualWidth) \ 2, VB.Printer.CurrentY, _
nActualWidth, Me.Height \ VB.Printer.TwipsPerPixelY, _
GetWindowDC(Me.hwnd), 0&, 0&, _
ScaleX(Me.Width, vbTwips, vbPixels), ScaleY(Me.Height, vbTwips, vbPixels), _
vbSrcCopy
VB.Printer.EndDoc
Busy 
-
January 2nd, 2006, 11:21 PM
#3
Re: Printing a Form in the center of the page
added this but cant figure out how to put it in the center i know this is close i added this so it would print landscape and my form called family it works but just in the top left corner
Code:
Dim nActualWidth&
VB.Printer.ScaleMode = vbPixels
nActualWidth = Me.Width \ VB.Printer.TwipsPerPixelX
Printer.Orientation = vbPRORLandscape
VB.Printer.Print
StretchBlt VB.Printer.hdc, (VB.Printer.ScaleWidth - nActualWidth) \ 2, VB.Printer.CurrentY, _
nActualWidth, Me.Height \ VB.Printer.TwipsPerPixelY, _
GetWindowDC(Me.hwnd), 0&, 0&, _
ScaleX(Me.Width, vbTwips, vbPixels), ScaleY(Me.Height, vbTwips, vbPixels), _
vbSrcCopy
family.PrintForm
VB.Printer.EndDoc
-
January 3rd, 2006, 12:57 AM
#4
Re: Printing a Form in the center of the page
no, the PrintForm method has its own printing routine so we have to avoid it in the code. by the way, our routine will center the form on the width (x) of the paper.
Code:
Option Explicit
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Sub Command1_Click()
PrintForm_LandScapeCenter Me
End Sub
Private Sub PrintForm_LandScapeCenter(frm As Form)
Dim nActualWidth&
VB.Printer.Orientation = vbPRORLandscape
VB.Printer.ScaleMode = vbPixels
nActualWidth = frm.Width \ VB.Printer.TwipsPerPixelX
VB.Printer.Print
StretchBlt VB.Printer.hdc, (VB.Printer.ScaleWidth - nActualWidth) \ 2, VB.Printer.CurrentY, _
nActualWidth, frm.Height \ VB.Printer.TwipsPerPixelY, _
GetWindowDC(frm.hwnd), 0&, 0&, _
frm.ScaleX(frm.Width, vbTwips, vbPixels), frm.ScaleY(frm.Height, vbTwips, vbPixels), _
vbSrcCopy
VB.Printer.EndDoc
End Sub
Busy 
-
January 3rd, 2006, 07:49 PM
#5
Re: Printing a Form in the center of the page
ok added this code it prints a blank page the name of my form is clients do i need to place this in my code????
-
January 3rd, 2006, 11:57 PM
#6
Re: Printing a Form in the center of the page
ok. if you mind posting your code here, might as well try something like this..
in a standard/bas module :
Code:
Option Explicit
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Public Sub PrintForm_LandScapeCenter(frm As Form)
Dim nActualWidth&
VB.Printer.Orientation = vbPRORLandscape
VB.Printer.ScaleMode = vbPixels
nActualWidth = frm.Width \ VB.Printer.TwipsPerPixelX
VB.Printer.Print
StretchBlt VB.Printer.hdc, (VB.Printer.ScaleWidth - nActualWidth) \ 2, VB.Printer.CurrentY, _
nActualWidth, frm.Height \ VB.Printer.TwipsPerPixelY, _
GetWindowDC(frm.hwnd), 0&, 0&, _
frm.ScaleX(frm.Width, vbTwips, vbPixels), frm.ScaleY(frm.Height, vbTwips, vbPixels), _
vbSrcCopy
VB.Printer.EndDoc
End Sub
and in your code, add this command/statement :
Code:
PrintForm_LandScapeCenter clients
Busy 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|