一、常用方法(已确认):
1
// Correct 是资源的名字,比如 Correct.png 资源的名字即为 Correct .
2
pictureBox1.Image = Properties.Resources.Correct;
二、使用 ResourceManager 类的方法(已确认):
01
// 1. 首先获取一个 ResourceManager 类的实例:
02
ResourceManager resourceManager = new ResourceManager("资源名称", Assembly.GetExecutingAssembly());
03
04
// 或如此:
05
ResourceManager resourceManager = newResourceManager(typeof(About));
06
07
// 或如此:
08
ResourceManager resourceManager = Properties.Resources.ResourceManager;
09
10
// 2. 通过 ResourceManager 类的 GetObject() 方法:
11
Object target = resourceManager.GetObject("资源文件名");
三、反射法(未确认):
1
Assembly assembly = this.GetType()。Assembly;
2
Stream stream = assembly.GetManifestResourceStream("Draw.Resources.Correct.jpg");
3
this.BackgroundImage = new Bitmap(stream);
四、资源文件读取类(未确认,可能会出问题):
01
using (ResXResourceReader reader = newResXResourceReader(@"About.resx"))
02
{
03
foreach (DictionaryEntry entry in reader)
04
{
05
if (entry.Key.ToString() == "MyName")
06
{
07
this.label2.Text = entry.Value.ToString();
08
}
09
}
10
}