答案 0 :(得分:3)
就像我说的那样,你不应该在控制台应用程序中使用Windows-UI,它说,这就是你如何按照你的要求做的。
我在我的本地机器上写了它并且它有效。
创建一个新的VB.Net控制台项目,并参考System.Windows.Forms
并将整个代码粘贴到module1.vb
(P.S.我将其更新为包含@Codexer的推荐,并在异常处理程序中包含错误消息。)
Imports System.Windows.Forms
Module Module1
<STAThread()> _
Sub Main()
Dim OpenFileDlg as new OpenFileDialog
OpenFileDlg.FileName = "" ' Default file name
OpenFileDlg.DefaultExt = ".txt" ' Default file extension
OpenFileDlg.Filter = "Text Files (*.txt)|*.TXT"
OpenFileDlg.Multiselect = True
OpenFileDlg.RestoreDirectory = True
' Show open file dialog box
Dim result? As Boolean = OpenFileDlg.ShowDialog()
' Process open file dialog box results
for each path in OpenFileDlg.Filenames
Try
System.Diagnostics.Process.Start(Path)
Catch ex As Exception
MsgBox("Error loading the file" & vbCrLf & ex.Message)
End Try
If result = True Then
' Open document
Else
Exit Sub
End If
next
End Sub
End Module
这是输出。