1

[VB.NET 2010]

Let's say I have several My.Resources items (each of which are plain text files that contain several paragraphs of text).

And let's say the resource item names correspond to different types of music, like My.Resources.Rock, My.Resources.Blues, My.Resources.Jazz, etc etc.

And based on what the user types into a text box, the program should access the correct My.Resources item, and display the text contents of that item in a rich text box.

For example, if the user types "Blues" into the text box, then I need to access the contents of My.Resources.Blues, and display it in the rich text box.

Something like this (doesn't work, of course)...

    Dim ResourceName As String = TextBox1.Text
    Dim ResourceContents As String = My.Resources.ResourceName
    RichTextBox1.Text = ResourceContents

Is there an easy way to accomplish this task?

4

1 回答 1

6

刚想出来,万一有人想知道...

Dim ResourceName As String = TextBox1.Text
Dim ResourceContents As String = My.Resources.ResourceManager.GetObject(ResourceName)
RichTextBox1.Text = ResourceContents
于 2012-10-29T22:53:04.553 回答