[ VB.NET ] OpenFileDialog 예제 본문

[PL]/VB & VB.NET

[ VB.NET ] OpenFileDialog 예제

객과 함께. 2009. 12. 29. 08:04

Imports System
Imports System.IO

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim txtNamePath As String
        Dim txtName As String
        Dim FileName As String

        OpenFileDialog1.Filter = "Text Files|*.txt"
        OpenFileDialog1.Title = "Text Read 예제"

        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            txtNamePath = OpenFileDialog1.FileName
            RichTextBox1.Text = ""
            If txtNamePath <> "" Then

                Try
                    FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
                    Do Until EOF(1)
                        txtName = LineInput(1)
                        RichTextBox1.Text = RichTextBox1.Text & txtName & vbCrLf
                    Loop
                Catch
                    MsgBox("Error opening file")
                Finally
                    FileClose(1)
                End Try
            End If

            Label1.Text = txtNamePath

            FileName = Mid(txtNamePath, InStrRev(txtNamePath, "\") + 1)

            Me.Text = " [ " & "TEXTBOX예제 - " & FileName & " ]"
        End If

    End Sub

'=========================================================================================================

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "TEXTBOX예제"
        Label1.Text = ""
        Button1.Text = "Read"
        Button2.Text = "Exit"
    End Sub

'==========================================================================================================

 

 

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
        End
    End Sub

End Class

 


'[PL] > VB & VB.NET' 카테고리의 다른 글

[ vb 2008 ] 사용자 컨트롤 매핑  (0) 2009.12.31
[ vb 2008 ] ListView 예제.  (0) 2009.12.30
[vb 2008]Try Catch 정리  (0) 2009.12.24
시계예제  (0) 2008.07.28
[vb.net 2005] 날자 및 시간 예제  (0) 2008.07.27