Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, June 19, 2015 10:23 PM
I have a simple winform app in VS2013. In the project properties I added a resource in the properties/resource tab. I would like to know how I can access this resource -- a string value -- which I could display in a messagebox for example:
--in Project Properties Resource tab I entered this
Name Value
TEST_TESTING this is a resource test
--in Resource.Designer.cs it looks like this:
namespace WindowsFormsApplication1.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WindowsFormsApplication1.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to this is a resource properties test.
/// </summary>
internal static string TEST_TESTING {
get {
return ResourceManager.GetString("TEST_TESTING", resourceCulture);
}
}
}
}
--and in the xml file it looks like this
<data name="TEST_TESTING" xml:space="preserve">
<value>this is a resource properties test</value>
</data>
</root>
in Form1 I would like to click a button and display the value of TEST_TESTING.
I saw one application that did this:
string str1 = _Resources.SOME_RESOURCE;
where _Resources is declared internally in the Designer.cs file, but when I try something like that in my sample app -- it doesn't work. What am I missing?
Rich P
All replies (2)
Friday, June 19, 2015 10:36 PM âś…Answered
Nevermind -- I figured it out
string str1 = WindowsFormsApplication1.Properties.Resources.TEST_TESTING;
Rich P
Monday, June 22, 2015 2:50 AM
Glad you've made it, and thanks for sharing your solution here.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.