C#中的dispose()和initializeComponent()方法会出现问题
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
表单设计器使用分部类 - 其中定义了
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 fromForm
yourself.Dispose
seems to be defined as well and isn't overrideable, so you don't need your method anyway.