为什么VS2017不断丢失我的派生控件? [英] Why does VS2017 keep losing my derived controls?

查看:83
本文介绍了为什么VS2017不断丢失我的派生控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序 namespace = DRT 中,我正在创建派生自其相应Windows控件类的控件类(例如按钮,文本框)。 >

In my app namespace = DRT, I'm creating control classes (e.g., button, textbox) that derive fron their corresponding Windows control classes, e.g.,

internal abstract class DRT_Button_Abstract : Button
{
    ....
}

internal class DRT_Button_CancelSearch : DRT_Button_Abstract
{
    ....
}

internal class DRT_Button_StartSearch : DRT_Button_Abstract
{
    ....
}

我目前总共拥有13个派生类,这些派生类来自于我的摘要或Windows控件类中的摘要。成功构建之后,我在工具箱上看到了我的控件类(例如 DRT_Button_CancelSearch DRT_Button_StartSearch ),并成功地将其删除他们到我的主要形式。暂时一切都很好,但是最终,我将打开主窗体。cs[Design](即UI设计器),它将显示错误变量'{control property name }'未声明或从未分配。用于我的控件的某些组合。

All together I currently have 13 derived classes that derive either from one of my abstracts or from a Windows control class. After a successful build, I see my control classes (e.g., DRT_Button_CancelSearch and DRT_Button_StartSearch) on the Toolbox and I successfully drop them onto my main form. All is fine for a while, but ultimately, I'll go to open the main form.cs [Design] (i.e., the UI designer) and it will show the error The variable '{control property name}' is either undeclared or was never assigned. for some combination of my controls.

当我检查主窗体Designer.cs文件时,除了预期的语句。它们不存在于主窗体Designer.cs文件中。例如,我希望看到 this.drt_Button_CancelSearch = new DRT.DRT_Button_CancelSearch(); 但缺少

When I examine the main form Designer.cs file, the expected code for all the controls is present EXCEPT for the expected new statement. They are not present in the main form Designer.cs file. For example, I expect to see this.drt_Button_CancelSearch = new DRT.DRT_Button_CancelSearch(); but its missing

I已经尝试忽略该错误,进入UI设计器窗口以重新应用丢失的控件,但是问题只是在新应用的控件中重复出现

I've tried ignoring the error, proceeding to the UI designer windows to re-apply the lost controls, but the problem just repeats with the newly applied control

这到底是什么继续吗有办法从这种情况中恢复吗?

What the heck is going on? Is there a way to recover from this situation?

推荐答案

这很可能是设计者无法清除/重新加载其缓存。您无能为力。过去,我:

This is most likely a problem of the Designer not being able to clear/reload its cache. There is not much you can do. In the past I:


  • 关闭并重新打开所有具有用户控件的设计器

  • 将所有单独项目中的控件(在同一解决方案中)

  • 将所有控件放入单独的解决方案/ Visual Studio实例中,并为控件的dll(甚至nuget包)设置适当的引用

在前两个选项中,我取得了不同的成功。重新打开设计器不是很方便,也不起作用。

With the first two options I have had varying success. Reopening the designer is not very convenient and doesn't work.

最后一个选择是最好的,但也是最烦人的,因为每次调整都需要重建项目并更新

That last option is the best but also the most annoying because every adjustment requires a rebuild of the project and update of the reference/package.

还请确保您创建的所有控件都具有公共默认构造函数,并且在使用此构造函数时功能良好。

Also make sure that all controls that you create have public default constructors and function well when this constructor is used.

这篇关于为什么VS2017不断丢失我的派生控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆