Reading a resource file -> for language settings f.i.

  • Thread starter Thread starter Screaming Eagles 101
  • Start date Start date
S

Screaming Eagles 101

This is not a question but something I found,
it might not be the best solution, but hey, it works... :-)
Thought someone else could also use this, so here it is.

I made 2 resource files, one for Dutch settings, one for English settings
In these resource files I store the control's name as item, and the text
(caption) of the control as its value.

First I check the language and parse this to my subroutine

'Check Language
sLang =
System.Globalization.CultureInfo.CurrentCulture.ToString.ToUpper.Substring(0,
2)

'Then I loop through all the controls:

Private Sub Setlanguage(ByVal sLang As String)
Dim ctrl As Control
Dim rm As Resources.ResourceManager

If sLang = "NL" Then
rm = My.Resources.Nederlands.ResourceManager
Else
rm = My.Resources.English.ResourceManager
End If

For Each ctrl In Me.Controls
If Not IsNothing(rm.GetString(ctrl.Name)) Then
ctrl.Text = rm.GetString(ctrl.Name)
End If
Next
End Sub

It's as simple as this....
--
Filip
http://www.ww2airborne.net/
Official Site of the 101st Airborne - 463rd PFA
skype: airborne463pfa-fiwi
[It's nice to be important, but it's more important to be nice!]
----------------------------------------------------------------
 
So what if a control has children (other controls).... ?
Like a panel for instance.... ?

Private Sub Setlanguage(ByVal sLang As String)
Dim ctrl As Control
Dim rm As Resources.ResourceManager

If sLang = "NL" Then
rm = My.Resources.Nederlands.ResourceManager
Else
rm = My.Resources.English.ResourceManager
End If

For Each ctrl In Me.Controls
SetControlCaptions(ctrl, rm)
Next

rm = Nothing
End Sub

Private Sub SetControlCaptions(ByVal pc As Control, ByVal pr As
Resources.ResourceManager)
Dim lc As Control
'recursive if the control has children
If pc.HasChildren Then
For Each lc In pc.Controls
SetControlCaptions(lc, pr)
Next
Else
'Lowest level, no children anymore - set the caption
If Not IsNothing(pr.GetString(pc.Name)) Then pc.Text =
pr.GetString(pc.Name)
End If
End Sub

--
Filip
http://www.ww2airborne.net/
Official Site of the 101st Airborne - 463rd PFA
skype: airborne463pfa-fiwi
[It's nice to be important, but it's more important to be nice!]
 
Back
Top