Dim strFileName ( ) As String '定义一个字符串数组 Dim OpenFileDialog1 As System.Windows.Forms.OpenFileDialog = New System.Windows.Forms.OpenFileDialog ( ) '创建一个OpenFileDialog实例 With OpenFileDialog1 .Filter = "Text files (*.txt)*.txtAll files (*.*)*.*" '设定文件类型过滤条件为:文本类型和全部文件 .FilterIndex = 1 '设定打开文件对话框缺省的文件过滤条件 .InitialDirectory = "C:/" '设定打开文件对话框缺省的目录 .Title = "打开文件" '设定打开文件对话框的标题 .Multiselect = True '设定可以选择多个文件 .ReadOnlyChecked = False '设定选中"只读"复选框 .ShowReadOnly = True '设定显示"只读"复选框 End With '设定打开文件对话框的式样和功能 If OpenFileDialog1.ShowDialog() = DialogResult.OK Then ' 显示打开文件对话框,并判定单击对话框中的"确定"按钮 strFileName = OpenFileDialog1.FileNames Dim s As String Dim i As Integer For i = 0 To strFileName.Length - 1 s = s + strFileName( i ) + Chr( 10 ) + Chr( 13 ) Next '处理打开文件选择框选择的文件 MessageBox.Show( s , "选择的文件名列表") End If
Dim PrintDocument1 As System.Drawing.Printing.PrintDocument = New System.Drawing.Printing.PrintDocument ( ) '创建一个打印文档 Dim PrintPreviewDialog1 As PrintPreviewDialog = New PrintPreviewDialog ( ) With PrintPreviewDialog1 .MaximizeBox = False .Text = "打印预览窗口" End With '设定打印预览窗口的属性 PrintPreviewDialog1.Document = PrintDocument1 PrintPreviewDialog1.ShowDialog ( )