Select 第一次选择的文件路径

Select file path on the first selection

我应该在此代码中更改什么?

当我打开对话框时,我只想选择一次文件,而不是两次选择文件路径。我必须选择文件路径两次才能将其显示在带有该代码的文本框中。

Private Sub BttImportY_Click(sender As Object, e As EventArgs) Handles BttImportY.Click
    TxtNumberListScan.Clear()
    ' Call ShowDialog.
    Dim result As DialogResult = OpenFileDialog1.ShowDialog()
    ' Test result.
    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
        ' Get the file name.
        Dim path As String = OpenFileDialog1.FileName
        ' Read in text.
        Dim text As String = File.ReadAllText(path)
        Dim lineCount = File.ReadAllLines(path).Length
        TxtCheckDraws.Text = TBIntDLX.Text - 1
        TxtNumberListScan.Text = System.IO.File.ReadAllText(path)
        TxtCheckL.Text = lineCount
        TxtCheckList.Text = TxtCheckL.Text - 1
    End If
End Sub

就是,去掉这一行:

Dim result As DialogResult = OpenFileDialog1.ShowDialog()