In my project I have a setting called DriveLetter and I wish to insert the value of this setting in to the text of several controls on a form (replacing a placeholder).
I thought the easiest way to do this would be to loop through each control on the form and search for the placeholder, but through trial and error I have discovered that I can't do that (at least in the way I'm trying) because I make use of Containers, such as the SplitContainer
and the Panel
.
Below is what I have so far, which takes in to account the aforementioned SplitContainer
and Panel
containesr, but how can I amend this to loop through every control on the form without having to explicitly check if the current control is a type of container?
Private DRIVE_LETTER As String = My.Settings.DriveLetter
'**
' Handle form loading
''
Private Sub form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
ReplaceDriveLetter(Me)
End Sub
'**
' Update the value of the <DRIVE_LETTER> text placehoder
''
Private Sub ReplaceDriveLetter(ByVal ctrlContainer As Control)
For Each ctrl As Control In ctrlContainer.Controls
If TypeOf ctrl Is SplitContainer Or TypeOf ctrl Is Panel Then
ReplaceDriveLetter(ctrl)
Else
ctrl.Text = Replace(ctrl.Text, "<DRIVE_LETTER>", UCase(DRIVE_LETTER))
End If
Next ctrl
End Sub
This should do it, although obviously replace the text here with the DriveLetter (I can help with that if you'd like).