后代通用表单无法在表单设计器中显示!
我有一个通用的基本表单,并且后代表单在设计器中不起作用。这显然是一个众所周知的问题,并且给出了相同的答案 此处和这里,仅举两个地方。
这个解决方案似乎适用于其他人,当我实现它时,至少我得到了一个不同的错误:
“无法找到适合指定区域性或中性区域性的任何资源。请确保“MyBaseForm`1.resources”正确在编译时嵌入或链接到程序集“MyAssembly”中,或者所需的所有附属程序集均可加载并完全签名。”
我的课程是:
public partial class MyBaseForm<T> : Form { }
#if DEBUG
public partial class MyIntForm_Design : MyBaseForm<int> {
}
#endif
public partial class MyIntForm
#if DEBUG
: MyIntForm_Design {
#else
: MyBaseForm<int> {
#endif
}
现在我必须跳过这里的哪个环?
编辑: 天哪,我发现了问题 - 嗯,有点。基本表单具有其 Icon
属性集,该属性集在资源文件中创建了一些内容。当我删除图标并重新编译时,基本表单突然可以工作了!
现在,这个问题的回答归功于找到解决方法的人,以便我可以将图标保留在我的基本形式中!
I have a generic base form, and the descendant forms don't work in the designer. This is apparently a well-known problem, and the same answer is given here and here, to name just two places.
This solution seems to work for everyone else, and when I implement it, at least I get a different error:
"Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "MyBaseForm`1.resources" was correctly embedded or linked into assembly "MyAssembly" at compile time, or that all the satellite assemblies required are loadable and fully signed."
My classes are:
public partial class MyBaseForm<T> : Form { }
#if DEBUG
public partial class MyIntForm_Design : MyBaseForm<int> {
}
#endif
public partial class MyIntForm
#if DEBUG
: MyIntForm_Design {
#else
: MyBaseForm<int> {
#endif
}
Now what hoop do I have to jump through here?
EDIT: OMG, I found the problem - well, sort of. The base form has its Icon
property set, which created something in the resource file. When I removed the icon and recompiled, the base form suddenly works!
Now answer credit for this question goes to whoever finds a workaround so that I can keep the icon in my base form!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,我发现了一个更简单的解决方法,每当您对通用基本表单进行外观更改时,它都不会面临被覆盖的风险:只需使通用表单从另一个具体表单
BaseForm
继承,其中 Icon 属性(以及任何其他资源)已设置。因此:
工作很愉快!
Actually I found an easier workaround that doesn't risk being overwritten whenever you make cosmetic changes to the generic base form: just make the generic form inherit from another concrete form
BaseForm
, where the Icon property (and any other resources) are set.Thus:
Works a treat!
继续我的评论,我设法让这个解决方案发挥作用:
修复嵌入式资源generic UserControl
它似乎正在做的是给资源一个不同的名称,以便删除通用类型,但将该名称与正确的类型相关联。在您的示例中,我执行了以下操作:
我将其放入通用基本控件的
InitializeComponent
中(我使用UserControl
进行测试),并修复了具体类的设计器。但是,我仍然必须包含中间类的解决方法来指定泛型参数的类型。这不会阻止设计器在重新生成时铺平您的更改,而且我知道没有办法将其从设计器代码中删除。该链接的原始发布者也有这个问题。然而,只要您记得这样做,以快速解决方案代替好处并不是一个坏的权衡!
Carrying on from my comments, I managed to get this solution to work:
Fix embedded resources for a generic UserControl
What it appears to be doing is giving the resource a different name so as to remove the generic type, but associating the name with the correct type. In your example I did the following:
I put this in the
InitializeComponent
of the generic base control (I used aUserControl
for my testing) and it fixed the designer of a concrete class. However, I still had to include the workaround of an intermediate class to specify a type for the generic argument.This does not stop the designer from paving your change when it regenerates, and I know of no way to remove it from the designer code. The original poster of that link also has this problem. However, the quick fix in lieu of the benefits is not a bad trade-off so long as you can remember to do it!