모든 라인을 읽으려면 Streamreader
및 ReadLine()
을, 저장하려면 List
을 권하고 싶습니다.
그래서 읽기 + 절약에 대한 코드는 다음과 같습니다
For i as Integer = 0 to lineList.Count - 1
Dim Label as New Label
lineLabel.Text = lineList.Item(i)
lineLabel.Location = New Point(0, 50 * i) 'you can change the 50 to whatever value you want
Me.Controls.Add(Label)
AddHandler Label.Click, AddressOf Me.Label_Click 'here we add a handler for the label-clicks
Next
핸들러이 다음과 같이 표시됩니다
Dim lineList As New List(Of String)()
Dim sr As StreamReader = New StreamReader(path)
Do While sr.Peek() >= 0
lineList.add(sr.ReadLine())
Loop
그런 다음 양식에 (텍스트가) 일부 레이블을 추가 :
Private Sub Label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'handle the label clicks here
End Sub
훨씬 여기가 진행되고 선택된 indexchanged 이벤트를 처리 할 수 있습니다. 배열에있는 전체 텍스트 파일을 덤핑하지만, 줄 당이 작업을 원하지 않는다면. 당신의 솔루션을 위해서 그냥 덤프 할 수 있습니다. 서식있는 텍스트 상자에 필요한 항목을 변경 한 다음 다시 저장하십시오. – Codexer
그래, 그렇게 생각하지 않을거야. 훨씬 빠르고 쉽습니다. 하지만 그것을 시작할 수 있습니까? 감사. –
텍스트 파일을 올바르게 읽거나 쓰는 방법을 알고 싶다면 http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx를 참조하십시오. http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx – cdMinix