如何用vb新建一个txt文本文件,将窗口中的内容保存到此txt文件中,并打印出来呢
2个回答
展开全部
窗体中有一个CommonDialog控件和一RichTextBox控件。没有的先添加部件。CommonDialog和RichTextBox。
open "c:\test.txt" for output as #1 '\\打开TEST.TXT
Put #1,me.Caption
close #1
RichTextBox1.Visible = False
RichTextBox1.text = me.Caption
'\\下面打印
With CommonDialog1
.DialogTitle = "Print"
.CancelError = True
.Flags = cdlPDReturnDC + cdlPDNoPageNums
If RichTextBox1.text .SelLength = 0 Then
.Flags = .Flags + cdlPDAllPages
Else
.Flags = .Flags + cdlPDSelection
End If
.ShowPrinter
If Err <> MSComDlg.cdlCancel Then
RichTextBox1.text .SelPrint .hDC
End If
End With
open "c:\test.txt" for output as #1 '\\打开TEST.TXT
Put #1,me.Caption
close #1
RichTextBox1.Visible = False
RichTextBox1.text = me.Caption
'\\下面打印
With CommonDialog1
.DialogTitle = "Print"
.CancelError = True
.Flags = cdlPDReturnDC + cdlPDNoPageNums
If RichTextBox1.text .SelLength = 0 Then
.Flags = .Flags + cdlPDAllPages
Else
.Flags = .Flags + cdlPDSelection
End If
.ShowPrinter
If Err <> MSComDlg.cdlCancel Then
RichTextBox1.text .SelPrint .hDC
End If
End With
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询