打印picturebox 中的Label textbox等

wolfloveu 2004-10-21 01:46:09
我在PICTUREBOX控件中用 Label 和textbox 控件做了一个复杂的表,如何才能将之存为位图打印出来?且大小根据纸张的大小调至合适?

我用了Printer.PaintPicture picture.image, 0, 0 只打印出一个空白的 picturebox控件,label控件和textbox 控件都没有显示,什么原因,请指教。
...全文
78 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
VBToy 2005-02-19
参考下面的吧,应该可以解决你的问题:
Option Explicit
Private validUser As Boolean

Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type


Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hDc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDCDest As Long, ByVal XDest As Long, ByVal YDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hDCSrc As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hDc As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDc As Long) As Long
Private Type PicBmp
Size As Long
Type As Long
hBMP As Long
hPal As Long
Reserved As Long
End Type

Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Function CreateBitmapPicture(ByVal hBMP As Long, ByVal hPal As Long) As Picture
On Error Resume Next
Dim R As Long

Dim pic As PicBmp
Dim IPic As IPicture
Dim IID_IDispatch As GUID


With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With


With pic
.Size = Len(pic)
.Type = vbPicTypeBitmap
.hBMP = hBMP
.hPal = hPal
End With

'建立Picture图象
R = OleCreatePictureIndirect(pic, IID_IDispatch, 1, IPic)
Set CreateBitmapPicture = IPic
End Function
Private Sub Command3_Click()
Dim x As Long, y As Long
Dim W As Long, H As Long
Dim s As String
Dim R As Single
If validUser = False Then
MsgBox "Invalid user!", vbInformation + vbOKOnly, "Invalid User"
Exit Sub
End If
Picture1.AutoRedraw = True
Dim hwndDeskTop As Long, hdcDesktop As Long
Me.ScaleMode = vbPixels
R = 0.9
'hwndDeskTop = GetDesktopWindow()
'hdcDesktop = GetWindowDC(hwndDeskTop)
Dim hDc As Long, hBMP As Long
hDc = CreateCompatibleDC(Me.hDc)
hBMP = CreateCompatibleBitmap(Me.hDc, CLng(Picture1.Width * R), Picture1.Height)
SelectObject hDc, hBMP
BitBlt hDc, 0, 0, CLng(Picture1.Width * R), Picture1.Height, Me.hDc, Picture1.Left, Picture1.Top, vbSrcCopy

'BitBlt Picture1.hDc, 0, 0, CLng(Picture1.Width * 9 / 10), Picture1.Height, Me.hDc, Picture1.Left, Picture1.Top, vbSrcCopy
'ReleaseDC hwndDeskTop, hdcDesktop
s = App.Path & "\BC" & Text1.Text & ".bmp"
'SavePicture Picture1.Image, s
SavePicture CreateBitmapPicture(hBMP, 0), s
DeleteObject hBMP
DeleteDC hDc

MsgBox "保存成功!" & vbCrLf & vbCrLf & "文件名为:" & s & vbCrLf & vbCrLf & "Copyright by Leo Xudong", vbOKOnly, "条形码保存"

End Sub
回复
sky9705 2005-02-19
楼上的,你一直帖这个,但这个不能解决问题。
只能打印里面的图象,之外就不行了。。
回复
badboy168 2004-10-21
picture1.scalemode=3
printer.scalemode=3
printer.paintpicture picture1.image ,0,0,picture1.width,picture.height
scale=3并不重要,不过一定要让printer.scalemode的值和picture1.scalemode的值相同,printer默认的打印单位为缇,1缇=1/20英寸
回复
GGL123 2004-10-21
http://www.china-askpro.com/msg2/qa05.shtml

http://www.china-askpro.com/msg11/qa15.shtml
回复
发动态
发帖子

1180

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
社区公告
暂无公告