我正在尝试实现一个 OpenFileDialog 框,它工作正常,除非我选择单击取消然后程序抛出一个错误,说找不到该文件,这让我感到困惑,因为我没有选择一个文件。
以下是代码。如何实现取消按钮?
OpenFileDialog1.InitialDirectory = "C:\"
OpenFileDialog1.FileName = "Select a Batch file..."
OpenFileDialog1.Filter = "Batch files (*.bat) | *.bat"
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then
OpenFileDialog1.Dispose()
End If
Dim R As New IO.StreamReader(OpenFileDialog1.FileName)
TextBox4.Text = R.ReadToEnd
R.Close()
Button4.Enabled = True
Button6.Enabled = True