C#中的dispose()和initializeComponent()方法会出现问题

发布于 2024-10-03 03:46:49 字数 1452 浏览 4 评论 0原文

我是 C# 新手,对我在标题中告诉您的方法有疑问。代码有点长,所以我将其发布到pastebin。我正在使用 32feet.net api 在列表中列出蓝牙设备。

问题出现在第 43 行和第 50 行,其中包含以下语句:

错误 1 ​​类型“WindowsFormsApplication1.Form1”已经定义了一个名为“Dispose”的成员,其参数类型相同 C:\Users\andre\documents\visual studio 2010\ Projects\blueetoth\blueetoth\Form1.cs 43 33 blueetoth

*错误 2 类型“WindowsFormsApplication1.Form1”已定义名为“InitializeComponent”的成员,其参数类型相同 C:\Users\andre\documents \visual studio 2010\Projects\blueetoth\blueetoth\Form1.cs 50 22 蓝牙 *

Pastebin: http://pastebin.com/LFEvaz2X

简短版本:dispose()

protected override void Dispose(bool disposing)
{
     base.Dispose(disposing);
}

简短版本:初始化组件

private void InitializeComponent()
    {
        this.mainMenu1 = new System.Windows.Forms.MainMenu();
        this.listBox1 = new System.Windows.Forms.ListBox();
        // 
        // listBox1
        // 
        this.listBox1.Location = new System.Drawing.Point(14, 14);
        this.listBox1.Size = new System.Drawing.Size(212, 212);
        // 
        // Form1
        // 
        this.ClientSize = new System.Drawing.Size(240, 268);
        this.Controls.Add(this.listBox1);
        this.Menu = this.mainMenu1;
        this.MinimizeBox = false;
        this.Text = "Form1";
        this.Load += new System.EventHandler(this.Form1_Load);

    }

I'm new to c# and have a problem with the methods i've told you in the title. the code is a little bit long so i posted it to pastebin. i'm using the 32feet.net api to list up bluetooth devices in a list.

the problems are in line 43 and 50 with the following statement:

Error 1 Type 'WindowsFormsApplication1.Form1' already defines a member called 'Dispose' with the same parameter types C:\Users\andre\documents\visual studio 2010\Projects\blueetoth\blueetoth\Form1.cs 43 33 blueetoth

and

*Error 2 Type 'WindowsFormsApplication1.Form1' already defines a member called 'InitializeComponent' with the same parameter types C:\Users\andre\documents\visual studio 2010\Projects\blueetoth\blueetoth\Form1.cs 50 22 blueetoth
*

Pastebin: http://pastebin.com/LFEvaz2X

short version: dispose()

protected override void Dispose(bool disposing)
{
     base.Dispose(disposing);
}

short version: initializeComponent

private void InitializeComponent()
    {
        this.mainMenu1 = new System.Windows.Forms.MainMenu();
        this.listBox1 = new System.Windows.Forms.ListBox();
        // 
        // listBox1
        // 
        this.listBox1.Location = new System.Drawing.Point(14, 14);
        this.listBox1.Size = new System.Drawing.Size(212, 212);
        // 
        // Form1
        // 
        this.ClientSize = new System.Drawing.Size(240, 268);
        this.Controls.Add(this.listBox1);
        this.Menu = this.mainMenu1;
        this.MinimizeBox = false;
        this.Text = "Form1";
        this.Load += new System.EventHandler(this.Form1_Load);

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

绝對不後悔。 2024-10-10 03:46:49

表单设计器使用分部类 - 其中定义了 InitializeComponent 方法。如果您想自己用代码创建表单,请不要使用设计器,而是创建一个普通的类并自己从 Form 派生。

Dispose 似乎也已定义并且不可重写,因此您无论如何都不需要您的方法。

The forms designer employs partial classes - the InitializeComponent method is defined there. If you want to create your form in code yourself, don't use the designer but create a normal class and derive from Form yourself.

Dispose seems to be defined as well and isn't overrideable, so you don't need your method anyway.

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