重构 Windows 窗体设计器代码

发布于 2024-08-27 22:50:28 字数 924 浏览 9 评论 0原文

我正在尝试将单个电机控制应用程序更新为控制未知数量电机的程序(在运行时添加电机控制)。旧的应用程序是非常静态地编写的,并依赖于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

§普罗旺斯的薰衣草 2024-09-03 22:50:28

不理解完整的问题,但您永远不应该修改生成的设计器代码,因此您只会丢失更改或破坏设计器。

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.

暗地喜欢 2024-09-03 22:50:28

您可以从 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文