我想在在执行通用对话框时,我所选择的.txt文本能在窗体上打印出来,但在下面那段程序中就是实现不了,请问各位高手怎么修改才能实现上面的功能。
程序代码如下:
Private Sub Command1_Click()
CommonDialog1.Action = 1
Label2.Caption = CommonDialog1.FileName
Open CommonDialog1.FileName For Input As #1
Do Until EOF(1)
   Input #1, a$
   Print a$
Loop
Close #1
End SubPrivate Sub Command2_Click()
End
End Sub

解决方案 »

  1.   

    另外还有两点:
    1、最好让内容显示在textbox或者label控件里面而不要直接打印在窗体上;
    2、如果打开的不是可读的文本文件,那么可能无法正常显示。
      

  2.   

    显示到Text1里面
    Private Sub Command1_Click()
    CommonDialog1.ShowOpen = 1
    Label2.Caption = CommonDialog1.FileName
    Open CommonDialog1.FileName For Input As #1
    Dim s As String
    Do Until EOF(1)
       Line Input #1, s
       Text1.Text = Text1.Text + s + VBCrlf
    Loop
    Close #1
    End SubPrivate Sub Command2_Click()
    End
    End Sub用上面的代码打开一个文本文件试试看。
      

  3.   

    不好意思,上面的代码中应该是CommonDialog1.ShowOpen,而没有=1
    另外把Text1的MultiLine属性设置为True
      

  4.   


    把你窗体的AutoRedraw属性设为True
      

  5.   

    我试了是可以
    但为什么不能在窗体上打印呢?
    还有“VBCrlf”在语句中用什么作用啊?谢谢
      

  6.   

    如果一定要显示在窗体上,就把窗体的AutoRedraw属性设为True
    vbcrlf是回车换行