Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
TextBox1.Text = OpenFileDialog1.FileName
End Sub
End Class
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click OpenFileDialog1.Filter = "Text File(*.txt)|*.txt|All File|*.*" OpenFileDialog1.Title = " OPEN File " OpenFileDialog1.InitialDirectory = "c:\" OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk TextBox1.Text = OpenFileDialog1.FileName End Sub End Class
PrivateSub button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs)
Dim myStream As Stream = NothingDim openFileDialog1 AsNew OpenFileDialog()
openFileDialog1.InitialDirectory = "c:\"
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = TrueIf openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK ThenTry
myStream = openFileDialog1.OpenFile()
If (myStream IsNotNothing) Then' Insert code to read the stream here.EndIfCatch Ex As Exception
MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
Finally' Check this again, since we need to make sure we didn't throw an exception on open.If (myStream IsNotNothing) Then
myStream.Close()
EndIfEndTryEndIfEndSub
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.Filter = "Text File(*.txt)|*.txt|All File|*.*"
OpenFileDialog1.Title = " OPEN File "
OpenFileDialog1.InitialDirectory = "c:\"
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
TextBox1.Text = OpenFileDialog1.FileName
End Sub
End Class
이 댓글을
이 댓글을