VB通用对话框打印遇到问题 求大神帮忙解决
我自己做了一个简单的程序用的是通用对话框 上面做了几个按钮第一个是打开命令按钮第二个是保存命令按钮 第三个打印按钮
Private Sub cmdOpen_Click()
Dim StrText As String
On Error GoTo Note '当出现错误时,跳转到Note语句
With CommonDialog1
.DialogTitle = "打开对话框"
.InitDir = "D:/"
.Filter = "Word文档(*.doc) |*.doc|文本文件(*.txt) |*.txt|所有文件(*.*) |*.*"
.FilterIndex = 1
Text1.Text = ""
.ShowOpen '或使用CommonDialog1.Action=1
Open .FileName For Input As #1
End With
If Err.Number = 0 Then '如果打开文件正确
Do While Not EOF(1)
Line Input #1, StrText
Text1 = Text1 + StrText + vbCrLf 'vbCrLf是系统常量,为回车换行符
'Text1=Text1+StrText+(Chr(13)+(Chr(10))
Loop
Close #1
End If
Note:
End Sub
Private Sub cmdPrinter_Click()
Dim i As Integer
CommonDialog1.ShowPrinter '或使用CommonDialog1.Action=5
For i = 1 To CommonDialog1.Copies
Printer.Print Text1.Text
Next i
Printer.EndDoc '结束打印
End Sub
Private Sub cmdSave_Click()
With CommonDialog1
.DialogTitle = "另存为对话框"
.InitDir = "C:/"
.Filter = "Word文档(*.doc)|*.doc|文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
.FilterIndex = 1
.DefaultExt = "*.Txt"
.Action = 2 '或使用CommondDialog1.ShowSave
Open .FileName For Output As #2
End With
For i = 1 To Len(Text1)
Print #2, Mid$(Text1, i, 1);
Next i
Close #2
End Sub
[此贴子已经被作者于2017-7-17 18:15编辑过]