|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problem Adding and Using Resource FilesI 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 > Am I missing something in regards to the structure of the text file or I assume you're using Visual Studio (?). If so then are you aware that it > perhaps how it is added? already has a built-in mechanism to handle strings for you (with relatively little work on your part)? 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 Show quoteHide quote "Larry Smith" <no_spam@_nospam.com> wrote in message news:ul6N7T3AHHA.5068@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)? >
Show quote
Hide quote
> Hey Larry, What I was alluding to is that you don't need to do this (or rather you're > > 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()) 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. 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 Show quoteHide quote "Larry Smith" <no_spam@_nospam.com> wrote in message news:uwO7gzBBHHA.4024@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. >
Learning OOP conceptual question
What do you call nested If...Then search loops? SortedList - bug or undocumented behavior ? Idle time File Aging Program convert idl to c# or tlb code collapsing in vb.net 2005 Find a control on a form of a specific name VB.NET Delegates Newbie: general requirements to write a program for video coding? |
|||||||||||||||||||||||