2012年6月6日 星期三

vbnet 開啟文字檔


Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Multiline = True
        TextBox1.ScrollBars = ScrollBars.Both
        '
        OpenFileDialog1.InitialDirectory = "c:\"
        OpenFileDialog1.Filter = "text file(*.txt)|*.txt|all file(*.*)|*.*"
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            'TextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)  '若沒定義編碼,預設會採用UTF8
            TextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName, System.Text.ASCIIEncoding.Default)
        End If
    End Sub
End Class


沒有留言:

張貼留言