473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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

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.To String.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!]
----------------------------------------------------------------
Oct 1 '07 #1
1 2184
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!]
Oct 2 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: ishmael4 | last post by:
hello everyone! i have a problem with reading from binary file. i was googling and searching, but i just cant understand, why isnt this code working. i could use any help. here's the source code:...
1
by: Michael Palmer | last post by:
I'm reading xml from SQL Server 2K with VB.net using an XSD schema file and SQLXML 3.0. I have the below code working fine, but I'd like to change the code from reading the schema file from a...
0
by: Josef Meile | last post by:
Hi, I'm working with .resx files for a multilanguage application and so far it has worked perfectly. However, now I want to add more attributes to the xml schema and read them at running time....
6
by: belmontpress | last post by:
I wish to delete some files from a directory after reading them but have the problem that the system says that the files are in use and cannot delete them even though I have set the StreamReader to...
1
by: ksen | last post by:
I hava a resource file "file1.resx" under App_GloabalResources folder . Could some one provide the sample code to read culture specfic resource file using ResourceReaded class. Thanks ksen
1
by: Georg Hickel | last post by:
Hi, in my app i need a script to setup a database. The script file is now read by the app with a streamreader. Now i want to read the script from an resource file which is embedded in my app. I...
4
by: Peter Larsen [] | last post by:
Hi, How do i read a resource string from a dll in code ?? BR Peter
0
by: jigsmshah | last post by:
I have a windows service developed in C#.I am reading the connection string from an ini file and also i am reading 3 image file from the bin directory. now the new requirement is that there will be...
6
by: Sabiyur | last post by:
Hi All, The application I am doing requires hundreds of strings to be stored & retrieve those randomly. I think I can use microsoft resource ".rc" file to store the strings. I am not sure, how...
2
by: Derik | last post by:
I've got a XML file I read using a file_get_contents and turn into a simpleXML node every time index.php loads. I suspect this is causing a noticeable lag in my page-execution time. (Or the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.