Hey Reverend Jim,
Hope you and your family are having a good time. I have a question about some code you posted about 3 yrs back. For the most part it is doing what I need but I cannot figure out an added feature that I want to give it. If you would give me a shout back...Greg
I found the code you posted pertaining to creating textboxes dynamically on a form using VB.net. Once the program is executed I have it place 246 textboxes on the form. After they are created I then read a text file and load each box with the text in the file. All of this works fine. I also have the .tag property to increment by 1 think I would use it to step throught the boxes when I save the form. I placed a "save" button on the form so if I make any changes I can save it back to the file or another file of my choosing. When I click on the button it saves the last line 245 times. How do I step through all of the textboxes so I can write the text of each box to the text file? When loading the form I have set the .tag property to increment by 1 think I would use it to step through the boxes when I save the form. I just cannot figure out how to use the .tag property to allow me to step through the textboxes to save each line of text. In the example I have the basic code only.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim FILE_NAME As String = "C:\Test.txt"
If File.Exists(FILE_NAME) = True Then
Dim objWriter As New StreamWriter(FILE_NAME)
For z As Integer = 1 To 245
objWriter.Write(newbox.Text & vbCrLf, False)
MessageBox.Show("Text written to file")
MessageBox.Show("File Does Not Exist")
Here is the snipet that creates the textboxes on the form. This works perfectly when it is included in my project.
For i As Integer = 1 To 245 ' 5 indecates the number of textbox you want to create.
'create a new textbox and set its properties
newbox = New TextBox
newbox.Tag = i
newbox.Size = New Drawing.Size(725, 20)
newbox.Location = New Point(10, 20 + 23 * (i - 1))
newbox.Text = sInputLine
sInputLine = srFileReader.ReadLine()
newbox.Name = "TextBox" & i
'connect it to a handler, save a reference to the array and add it to the form controls
AddHandler newbox.TextChanged, AddressOf TextBox_TextChanged_1
boxes(i) = newbox