我在PICTUREBOX控件中用 Label 和textbox 控件做了一个复杂的表,如何才能将之存为位图打印出来?且大小根据纸张的大小调至合适?我用了Printer.PaintPicture picture.image, 0, 0 只打印出一个空白的 picturebox控件,label控件和textbox 控件都没有显示,什么原因,请指教。
解决方案 »
- 求个网卡驱动程序
- 这种情况下的 CommonDialog1.ShowSave VB代码怎么写
- 关于WebBrowser中的图片的问题
- 在线等:求一段程序(内祥,给出网址也可)谢谢
- 怎样把vc中的句柄变成vb中的控件进行处理.
- 近来上网,当打开一些跳出的页面时,经常在状态栏上出现"已完成,但网页有错误用"的提示,而网页就打不开,怎样解决?
- 请问怎么样才能使自己的程序尽可能的小?(程序功能不减)
- 用ado如何根据一个字段值把recordset快速定位到一个记录?
- 使用MSHFLEXGRID控件,如何实现当左右滚动时将左边的几列冻结的目的??
- 怎么样把内容输入到文本文件中 并且要换行
- 介绍个能下载VB元代码的地方啊!!
- VB6自带的打包程序制作的安装包在别的机子上提示文件版本高要重启,重启后还要重启..........
printer.scalemode=3
printer.paintpicture picture1.image ,0,0,picture1.width,picture.height
scale=3并不重要,不过一定要让printer.scalemode的值和picture1.scalemode的值相同,printer默认的打印单位为缇,1缇=1/20英寸
Option Explicit
Private validUser As BooleanPrivate 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 TypePrivate 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