question to set up an array of controls or not??
Ok as I have posted before I am a newbie to this so please be gentle...
I have a tabbed form with numerous text boxes on, now some of these text boxes are related to one another whilst others aren't.
e.g.
tab1
[MH1] [MH2] [MH3] [MH4] [MH5]
[MH6] [MH7] [MH8] [MH9]
[MH10]
tab2
[MH11] [MH12] [MH13] [MH14] [MH15]
[MH16] [MH17] [MH18] [MH19]
[MH20]
MH1 TO MH10 are all related as are MH11 TO MH20, however MH1 to MH5 form a line of output to a file, MH6 to MH9 form the next line and MH10 the next. MH11 to MH15 form the next line of output and so on til MH20.
Question: Is it best to set up a array of text boxes for each seperate line of output?? Also what is the best way to read each/all these text boxes to check the data that has been input?
regards,
Matt
Re: question to set up an array of controls or not??
It is easier to create these at run time, although you need to work out their positions.
Code:
Dim TB(10) As TextBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
For i As Integer = 0 To 10 - 1
'Make a new textbox
TB(i) = New TextBox
'Set the textbox name
TB(i).Name = "TB" & i.ToString
'Add a handler for the text changed event
AddHandler TB(i).TextChanged, AddressOf HandleAllTextBoxes
'Add the textbox to the form
Me.Controls.Add(TB(i))
'Arrange text boxes as three rows of 5, 4 and 1
'You can probably write this bit more efficiently
TB(i).Left = 5
If i = 0 Then
TB(i).Top = 5
ElseIf i = 5 Then
TB(i).Top = TB(0).Top + TB(i).Height + 5
ElseIf i = 9 Then
TB(i).Top = TB(0).Top + TB(i).Height * 2 + 5 * 2
Else
TB(i).Top = TB(i - 1).Top
TB(i).Left = TB(i - 1).Right + 5
End If
Next
'To examine each textbox, use a loop like this
For i As Integer = 0 To TB.GetUpperBound(0) - 1
'Check the contents of each box TB(0) to TB(n)
Next
End Sub
Private Sub HandleAllTextBoxes(ByVal sender As Object, ByVal e As System.EventArgs)
'Do stuff
MessageBox.Show("Textbox " & CType(sender, TextBox).Name.ToString & " was changed.")
End Sub
You can create a sub like this for each tab, or have one sub that creates and handles all textboxes on all tabs.
Re: question to set up an array of controls or not??
Thanx for the help will give it a try tommorow.
regards,
Matt