Prev: DataGridView Edit row marker
Next: The 'urn:schemas-microsoft-com:xml-msdatasource:DataSetUISetting' element is not declared.
From: TCook on 8 Nov 2006 13:51 Hey All, I am building a solution which will have many strings that will need to be localized (i.e. strings for toolbars, strings for different WinForms, strings for messages and error messages, etc.). I am having trouble accessing string file resources. What I want to do is to break out strings into separate files so that they are easier to manage and such that I don't have to look through hundreds to find, edit or delete something. How can I use code similar to that below: Dim rm As ResourceManager Dim Message as StringBuilder rm = New ResourceManager("StringTable", Me.GetType().Assembly) Message = New StringBuilder() Message.Append(rm.GetString("String1")) Message.Append(rm.GetString("String2")) MessageBox.Show(Message.ToString()) Right now, when I try the above I get an error claiming that such resources cannot be found. The text file is listed under the resources. What's wrong? Am I missing something in regards to the structure of the text file or perhaps how it is added? Please advise. Thanks, TC
From: Larry Smith on 8 Nov 2006 15:32 > Am I missing something in regards to the structure of the text file or > perhaps how it is added? I assume you're using Visual Studio (?). If so then are you aware that it already has a built-in mechanism to handle strings for you (with relatively little work on your part)?
From: TCook on 8 Nov 2006 18:42 Hey Larry, As I mentioned in the original post, I am using the stings available under "Resources". What I am asking for is a way to segregate these strings into intelligent collections probably via separate files. That said, how can I load and use separate resource files into the list of resources? How can I use code similar to that below: Dim rm As ResourceManager Dim Message as StringBuilder rm = New ResourceManager("StringTable", Me.GetType().Assembly) Message = New StringBuilder() Message.Append(rm.GetString("String1")) Message.Append(rm.GetString("String2")) MessageBox.Show(Message.ToString()) Regards, TC "Larry Smith" <no_spam@_nospam.com> wrote in message news:ul6N7T3AHHA.5068(a)TK2MSFTNGP02.phx.gbl... >> Am I missing something in regards to the structure of the text file or >> perhaps how it is added? > > I assume you're using Visual Studio (?). If so then are you aware that it > already has a built-in mechanism to handle strings for you (with > relatively little work on your part)? >
From: Larry Smith on 9 Nov 2006 11:34 > Hey Larry, > > As I mentioned in the original post, I am using the stings available under > "Resources". > > What I am asking for is a way to segregate these strings into intelligent > collections probably via separate files. > > That said, how can I load and use separate resource files into the list of > resources? > > How can I use code similar to that below: > > Dim rm As ResourceManager > Dim Message as StringBuilder > > rm = New ResourceManager("StringTable", Me.GetType().Assembly) > > Message = New StringBuilder() > Message.Append(rm.GetString("String1")) > Message.Append(rm.GetString("String2")) > MessageBox.Show(Message.ToString()) What I was alluding to is that you don't need to do this (or rather you're probably making your life more difficult). First, ".resx" files for forms are handled automatically by VS (referring to all strings that appear on your forms for instance). If you're not aware of the details please let me know (it seems that way). For other resources like error messages and so forth, go to Solution Explorer and right-click your project's node. Select "Properties" from the context menu and click "Resources" on the left-hand side. A table now appears where you can enter all (non-form) resources which are usually strings (you may have to click on the notice in the middle of the window first if there is one - it will be present if it's the first time doing this). VS then creates a wrapper class called "Resources" where you can now access any single resource (string or whatever) via the <YourProjectNamespace>.Properties.Resources.<ResourceName> static property (a "using <YourProjectNamespace>.Properties" statement is required in each source file of course). For instance, if you add "MyString=Whatever" to the table and your project's namespace is "YourProjectNamespace", you can do this: using YourProjectNamespace.Properties; // ... string MyString = Resources.MyString; You can access all resources this way, not just strings.
From: TCook on 9 Nov 2006 13:13
Hey Larry, Yes, I am already using the catch-all resources file and I'm also using the resource files exposed to userforms. My question is, if I want to, how can I break the strings in the catch-all resource out into separate files? Regards, Todd "Larry Smith" <no_spam@_nospam.com> wrote in message news:uwO7gzBBHHA.4024(a)TK2MSFTNGP04.phx.gbl... >> Hey Larry, >> >> As I mentioned in the original post, I am using the stings available >> under "Resources". >> >> What I am asking for is a way to segregate these strings into intelligent >> collections probably via separate files. >> >> That said, how can I load and use separate resource files into the list >> of resources? >> >> How can I use code similar to that below: >> >> Dim rm As ResourceManager >> Dim Message as StringBuilder >> >> rm = New ResourceManager("StringTable", Me.GetType().Assembly) >> >> Message = New StringBuilder() >> Message.Append(rm.GetString("String1")) >> Message.Append(rm.GetString("String2")) >> MessageBox.Show(Message.ToString()) > > What I was alluding to is that you don't need to do this (or rather you're > probably making your life more difficult). First, ".resx" files for forms > are handled automatically by VS (referring to all strings that appear on > your forms for instance). If you're not aware of the details please let me > know (it seems that way). For other resources like error messages and so > forth, go to Solution Explorer and right-click your project's node. Select > "Properties" from the context menu and click "Resources" on the left-hand > side. A table now appears where you can enter all (non-form) resources > which are usually strings (you may have to click on the notice in the > middle of the window first if there is one - it will be present if it's > the first time doing this). VS then creates a wrapper class called > "Resources" where you can now access any single resource (string or > whatever) via the > <YourProjectNamespace>.Properties.Resources.<ResourceName> static property > (a "using <YourProjectNamespace>.Properties" statement is required in each > source file of course). For instance, if you add "MyString=Whatever" to > the table and your project's namespace is "YourProjectNamespace", you can > do this: > > using YourProjectNamespace.Properties; > // ... > string MyString = Resources.MyString; > > You can access all resources this way, not just strings. > |