C#資源文件與與資源名稱字符串之間的互相轉化
阿新 • • 發佈:2018-08-30
NPU 資源文件 val ret gets gen ati bject log 原文:C#資源文件與與資源名稱字符串之間的互相轉化
1.使用ResourceManager
string st = Properties.Resources.ResourceManager.GetString(tableName);
value = Properties.Resources.ResourceManager.GetObject(fileName, Properties.Resources.Culture)
public static Bitmap GetImageByName(string imageName)
{
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
string resourceName = asm.GetName().Name + ".Properties.Resources";
var rm = new System.Resources.ResourceManager(resourceName, asm);
return (Bitmap)rm.GetObject(imageName);
}
2. 使用反射
var type = typeof(Properties.Resources);
var property = type.GetProperty(fileName, BindingFlags.Static| BindingFlags.NonPublic|BindingFlags.Public);
var value = property.GetValue(null, null);
C#資源文件與與資源名稱字符串之間的互相轉化