重构 Windows 窗体设计器代码
我正在尝试将单个电机控制应用程序更新为控制未知数量电机的程序(在运行时添加电机控制)。旧的应用程序是非常静态地编写的,并依赖于 Windows 窗体设计器来生成其视图。我正在尝试重构设计器代码,以便基本上仅在选项卡页内显示多个出现的情况。我已经在使用 Windows 表单设计器时遇到错误。当我尝试将组件的初始化提取到它们自己的方法中时,出现错误:
Method 'System.Windows.Forms.Form.InitializeForceIsMaintained' not found.
How do I Tell C# I Want to use the local method and not somehired method?
我像这样调用
private Void InitializeComponent()
{
this.InitializeForceIsMaintained();
}
InitializeForceIsMaintained
private void InitializeForceIsMaintained()
{
//
// forceIsMaintained
//
this.forceIsMaintained.AutoReset = false;
this.forceIsMaintained.Interval = 8000;
this.forceIsMaintained.SynchronizingObject = this;
this.forceIsMaintained.Elapsed += this.forceIsMaintained_Elapsed;
}
I am trying to update a single motor control application into a program that controls an unknown number of motors(adding motor controls at runtime). The old application was written very statically and relied on windows form designer to generate its views. I am trying to refactor the designer code to basically just display multiple occurrences each inside a Tab Page. I am already running into errors with Windows form designer. When I try and pull the initialization of components out into their own methods I get an error:
Method 'System.Windows.Forms.Form.InitializeForceIsMaintained' not found.
How do I tell C# I want to use the local method and not some inherited method?
I'm calling InitializeForceIsMaintained like so
private Void InitializeComponent()
{
this.InitializeForceIsMaintained();
}
and
private void InitializeForceIsMaintained()
{
//
// forceIsMaintained
//
this.forceIsMaintained.AutoReset = false;
this.forceIsMaintained.Interval = 8000;
this.forceIsMaintained.SynchronizingObject = this;
this.forceIsMaintained.Elapsed += this.forceIsMaintained_Elapsed;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不理解完整的问题,但您永远不应该修改生成的设计器代码,因此您只会丢失更改或破坏设计器。
Don't understand the complete problem, but you should never modify the designer code as its generated, so you'll only either lose your changes or break the designer.
您可以从 System.Windows.Forms.Form 继承对象,然后重写有问题的方法吗?然后它会选择使用您的 Forms.Form 类中的默认值而不是默认值。
Can you inherit your objects from System.Windows.Forms.Form and then override the method in question? Then it would choose to use yours instead of the default one in the Forms.Form class.