VB VSPrinter 从外部引入一个.emf文件设定A4纸打印,之后保存为.pdf文件
麻烦各位写个模板,加上一些注释
改改名字路径就能用的那那种.
我刚刚接触这个,不是很懂,请各位多多指教,谢谢!
好用的话,给加分!
VB VSPrinter 从外部引入一个emf文件设定A4纸打印,之后保存为pdf文件格式
答案:2 悬赏:10 手机版
解决时间 2021-01-26 05:10
- 提问者网友:川水往事
- 2021-01-25 12:38
最佳答案
- 五星知识达人网友:有你哪都是故乡
- 2021-01-25 13:19
建立一个PictureBox1,窗体中引用API,在得到CDN_SELCHANGE时,调用GetFilesName得到此时用户选中的 文件,代码如下:
Private Function GetFilesName(hWindow As Long) As String
Dim hParent As Long
Dim lRetValue As Long
Dim theFileName(1024) As Byte
For i = 0 To UBound(theFileName)
theFileName(i) = 0
Next
hParent = GetParent(hWindow)
lRetValue = SendMessage(hParent, CDM_GETFILEPATH, 1024, theFileName(0))
GetFilesName = StrConv(theFileName, vbUnicode)
End Function
调用GetOpenFileName API的方法如下:
Public Function ShowOpenFileDlg(hParent As Long) As Long
On Error GoTo lblExit
Static strFilter As String
strFilter = "All Pictures" & Chr(0) & "*.bmp;*.dib;*.jpg;*.gif;*.wmf;*.emf;*.ico;*.cur" & Chr(0) & _
"Bitmap (*.bmp;*.dib)" & Chr(0) & "*.bmp;*.dib" & Chr (0) & _
"JPEG (*.jpg)" & Chr(0) & "*.jpg" & Chr(0) & _
"GIF (*.gif)" & Chr(0) & "*.gif" & Chr(0) & _
"Metafile (*.wmf;*.emf)" & Chr(0) & "*.wmf;*.emf" & Chr(0) & _
"Icons (*.ico;*.cur)" & Chr(0) & "*.ico;*.cur" & Chr (0) & _
"All files (*.*)" & Chr(0) & "*.*" & Chr(0) & Chr (0)
FrmPreview.Hide
pointer = GetProcAddr(AddressOf wndProc)
Dim MyID As Long
With openfile
.lStructSize = Len(openfile)
.hwndOwner = hParent
.hInstance = App.hInstance
.lpstrFilter = strFilter
.lpstrCustomFilter = ""
.nMaxCustFilter = 0
.nFilterIndex = 0
.lpstrFile = filesname
.nMaxFile = 1023
.lpstrFileTitle = ""
.nMaxFileTitle = 0
.lpstrInitialDir = ""
.lpstrTitle = ""
.flags = OFN_ENABLEHOOK + OFN_HIDEREADONLY + OFN_ENABLETEMPLATE + OFN_EXPLORER
.nFileOffset = 0
.nFileExtension = 0
.lpstrDefExt = ""
.lCustData = 0
.lpfnHook = pointer
.lpTemplateName = "DLGOPENTEMP"
End With
ShowOpenFileDlg = GetOpenFileName(openfile)
lblExit:
End Function
在窗体中CALL函数模块,让Picture装载到VSPrint,,设置代码如下:
'---------------------预览报表
VSPrinter1.StartDoc
VSPrinter1.Zoom = 100 '显示比例为100%
VSPrinter1.RenderControl = Form1.Picture1.hWnd
'----------------------设置
With VSPrinter1
'设置标题
.FontSize = 16
.FontBold = True
.TextAlign = taCenterMiddle
.Paragraph = "打印人:张三"
.Footer = "打印日期: " & Format(Date, "yyyy/mm/dd ") & " 第 " & ipage & "页,共 " & pages & "页 "
.FontBold = True
.FontSize = 10
.TextAlign = taRightTop
.Paragraph = " "
.FontBold = False
.FontSize = 10
End With
VSPrinter1.EndDoc
Private Function GetFilesName(hWindow As Long) As String
Dim hParent As Long
Dim lRetValue As Long
Dim theFileName(1024) As Byte
For i = 0 To UBound(theFileName)
theFileName(i) = 0
Next
hParent = GetParent(hWindow)
lRetValue = SendMessage(hParent, CDM_GETFILEPATH, 1024, theFileName(0))
GetFilesName = StrConv(theFileName, vbUnicode)
End Function
调用GetOpenFileName API的方法如下:
Public Function ShowOpenFileDlg(hParent As Long) As Long
On Error GoTo lblExit
Static strFilter As String
strFilter = "All Pictures" & Chr(0) & "*.bmp;*.dib;*.jpg;*.gif;*.wmf;*.emf;*.ico;*.cur" & Chr(0) & _
"Bitmap (*.bmp;*.dib)" & Chr(0) & "*.bmp;*.dib" & Chr (0) & _
"JPEG (*.jpg)" & Chr(0) & "*.jpg" & Chr(0) & _
"GIF (*.gif)" & Chr(0) & "*.gif" & Chr(0) & _
"Metafile (*.wmf;*.emf)" & Chr(0) & "*.wmf;*.emf" & Chr(0) & _
"Icons (*.ico;*.cur)" & Chr(0) & "*.ico;*.cur" & Chr (0) & _
"All files (*.*)" & Chr(0) & "*.*" & Chr(0) & Chr (0)
FrmPreview.Hide
pointer = GetProcAddr(AddressOf wndProc)
Dim MyID As Long
With openfile
.lStructSize = Len(openfile)
.hwndOwner = hParent
.hInstance = App.hInstance
.lpstrFilter = strFilter
.lpstrCustomFilter = ""
.nMaxCustFilter = 0
.nFilterIndex = 0
.lpstrFile = filesname
.nMaxFile = 1023
.lpstrFileTitle = ""
.nMaxFileTitle = 0
.lpstrInitialDir = ""
.lpstrTitle = ""
.flags = OFN_ENABLEHOOK + OFN_HIDEREADONLY + OFN_ENABLETEMPLATE + OFN_EXPLORER
.nFileOffset = 0
.nFileExtension = 0
.lpstrDefExt = ""
.lCustData = 0
.lpfnHook = pointer
.lpTemplateName = "DLGOPENTEMP"
End With
ShowOpenFileDlg = GetOpenFileName(openfile)
lblExit:
End Function
在窗体中CALL函数模块,让Picture装载到VSPrint,,设置代码如下:
'---------------------预览报表
VSPrinter1.StartDoc
VSPrinter1.Zoom = 100 '显示比例为100%
VSPrinter1.RenderControl = Form1.Picture1.hWnd
'----------------------设置
With VSPrinter1
'设置标题
.FontSize = 16
.FontBold = True
.TextAlign = taCenterMiddle
.Paragraph = "打印人:张三"
.Footer = "打印日期: " & Format(Date, "yyyy/mm/dd ") & " 第 " & ipage & "页,共 " & pages & "页 "
.FontBold = True
.FontSize = 10
.TextAlign = taRightTop
.Paragraph = " "
.FontBold = False
.FontSize = 10
End With
VSPrinter1.EndDoc
全部回答
- 1楼网友:洎扰庸人
- 2021-01-25 14:26
没用过VSPRINTER控件,对方必定给你一些说明和示例的.你查看一下或咨询控件的提供方吧.
再看看别人怎么说的。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯