2

So I've created several strings in my Resources.resx file and compiled my project so now in Resources.Designer.cs I have a list of "internal static string"s that look something like this:

internal static string header {
    get {
        return ResourceManager.GetString("header", resourceCulture);
    }
}

If I wanted to set a string in my main to the value of the string 'header', how would I do so?

P.S. I did search for this question already but none of the answers helped.

EDIT: I do not want to change this to a dynamic string, static is fine. I simply want to know what the syntax is to access these strings I've saved in my resources.

Capn Jack
  • 1,201
  • 11
  • 28
  • your resource has probably the Access Modifier set as Internal, set the Access Modifier to Public and you will be able to access the resource from another part. – avi Sep 28 '16 at 13:31
  • @TaW are you sure this is a duplicate? he is not asking to modify the resource...he is asking how to set a string in his main with the value of a resource... – avi Sep 28 '16 at 13:32
  • @avi doesn't internal mean anything in the same assembly can access it? Am I not in the same assembly as it? – Capn Jack Sep 28 '16 at 13:32
  • @Taw the linked article doesn't help me at all. I'm asking for the syntax for accessing the strings I've made in my resources, not how to change it from static to dynamic. – Capn Jack Sep 28 '16 at 13:33
  • Was just about to post an answer for OP. but its now closed... – testydonkey Sep 28 '16 at 13:36
  • @testydonkey was it closed by a bot? I made an edit explaining why the duplicate is wrong and made a comment to... Still marked as dupe. Would you mind posting the answer here or maybe I should repost the question? – Capn Jack Sep 28 '16 at 13:37
  • I don't think it's a dupe. So here's an answer as comment. :) Select your *.resx* in _Solution Explorer_. Press *F4* to get *Properties*. Change *Custom Tool* to `PublicResXFileCodeGenerator`. It will change your internal properties to public. – smoksnes Sep 28 '16 at 13:44
  • 1
    This is how I do it. 1) click on the resources file and go to properties and set - Build Action - Embedded Resource - Custom Tool - PublicResXFileCodeGenerator - Custom Tool NameSpaces -ProjectName.Resources [![See here][1]][1] [1]: http://i.stack.imgur.com/cs1HA.png Then to use them you can do it like so Resources.AdminResources.Button_Edit – testydonkey Sep 28 '16 at 13:44
  • 1
    ^^ lol formatting – testydonkey Sep 28 '16 at 13:45
  • @smoksnes Okay I've done that now but how do store the value into a string variable? Or say print the string to a message box? I tried doing something like: string newString = header. But header isn't recognized as an existing string. What's the literal syntax to use these strings from my resources? – Capn Jack Sep 28 '16 at 13:52
  • 1
    @CapnJack - As @testydonkey said. You should be able to use them as `[Namespace].Resources.Header`. It will be a static string that fetches the string from `ResourceManager`. If not, open your resx again after changing Custom Tool and make sure that the cs-file i re-generated. – smoksnes Sep 28 '16 at 13:55
  • Ah okay I finally got it thanks so much you two. And for future reference I found my path to be: [NameSpace].Properties.Resources.nameOfString – Capn Jack Sep 28 '16 at 14:00
  • @test: It is open again now. I thought he really __had__ searched and found no way to change the resource because there is none. – TaW Sep 28 '16 at 14:17

1 Answers1

2

This is how I do it.

1) click on the resources file and go to properties and set

  • Build Action - Embedded Resource

  • Custom Tool - PublicResXFileCodeGenerator

  • Custom Tool NameSpaces -ProjectName.Resources

See here

Then to use them you can do it like so

Resources.AdminResources.Button_Edit
testydonkey
  • 149
  • 4