我有一个使用多个OpenFileDialog
的程序,但我想使用一个。{我编写了一个代码来执行此操作,但有更简单的方法吗?
Public Class Form1
Private _intFlag As Integer = 0
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
_intFlag = 1
OpenFileDialog1.ShowDialog()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
_intFlag = 2
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
If _intFlag = 1 Then
TextBox1.Text = OpenFileDialog1.FileName
ElseIf _intFlag = 2 Then
TextBox2.Text = OpenFileDialog1.FileName
End If
End Sub
End Class
答案 0 :(得分:2)
我建议不要处理FileOk
事件。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
TextBox1.Text = OpenFileDialog1.FileName
End If
End Sub
和其他Button
类似。