|
问题F 为什么修改了窗体类的名称以后,总是提示资源错误?
使用Visual Studio 2008 的C++ 建立CLR窗体工程时,系统会使用默认的模板,此时,
窗体的名称是Form1,窗体文件为Form1.h。是不是很不爽?于是开始依次修改:
1、首先通过属性窗口修改类名称——注意,尽可能不要手动修改代码,而使用属性窗口
来修改,方法是打开窗体的代码视图,选中窗体类。此时,属性窗口中出现了该类的
各种属性,直接修改名称即可。
2、接下来,我们要修改文件名称,总之form1.h看起来很不爽。仍然不要手动修改文件
名称,选中窗体文件Form1.h,然后在属性窗口中修改名称。
3、编译,肯定会出现错误,不过都是一些#include文件名称的小错误,很容易解决。
4、再次编译,通过,但是运行时刻,总能看到如下的错误提示:
观察控制台,提示资源加载错误,找不到所需的资源文件:
<font color=blue>Additional information: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "DeviceSpaceTest.frmDeviceSpaceTest.resources" was correctly embedded or linked into assembly "DeviceSpaceTest" at compile time, or that all the satellite assemblies required are loadable and fully signed.
这是为什么呢?
大惑不解:于是仔细查看代码,发现在窗体类的定义之前,有一段小注释:
/// <summary>
/// Summary for frmDeviceSpaceTest
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
看来和资源文件有关系,于是按照上面的提示,尝试解决问题:
1、选中工程->属性(Propertis)->配置属性(Configuration Properties)
->托管资源(Managed Resource)->资源文件名称(Resource File Name)
2、强制将$(InputName)修改为窗体文件名称(假如你的窗体文件名成为frmDeviceSpaceTest),则
一个典型的修改结果为:
$(IntDir)\$(RootNamespace).frmDeviceSpaceTest.resources
单机应用。
3、清除工程(Clean)、重新编译(Rebuild),然后运行,故障解除。
4、重新通过步骤2,将刚才修改的名字改回$(InputName),因为二者是等价的。上面的强制修改迫使
VS2008重新进行了某些更新——鬼知道,也许是一个BUG。
问题解决,大功告成……(累 - -b) |
|