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
Printable View
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
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
ImplemetationCode: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
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
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
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
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????
ok. if you mind posting your code here, might as well try something like this..
in a standard/bas module :
and in your code, add this command/statement :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
Code:PrintForm_LandScapeCenter clients