VB 打开对话框
Public Class Form1
Private strFileName As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With OpenFileDialog1
.Filter = "Text Documents (*.txt)|*.txt|All Files(*.*)|*.*"
.FilterIndex = 1
.Title = "demo open file"
End With
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Try
strFileName = OpenFileDialog1.FileName
Dim fileContents As String
fileContents = My.Computer.FileSystem.ReadAllText("strFileName")
TextBox1.Text = fileContents
Catch ex As Exception
MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
End Class