[ VB.NET ] OpenFileDialog 예제
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