[英]Why im getting error on the line InitializeComponent();?
我有这个Usercontrol,我创建并且我在InitializeComponent
上遇到错误
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Synthesis;
namespace RssNews
{
public partial class
FeederControl : UserControl
{
SpeechSynthesizer speaker;
Label[] list = new Label[5];
int jump = 0;
private IContainer components;
public string[] NewsTextFeed { get; set; }
public Color[] TextColor { get; set; }
private int _spacing = 10;
public int Spacing
{
get { return _spacing; }
set { _spacing = value; }
}
public void NewsFeederControl()
{
InitializeComponent();
speaker = new SpeechSynthesizer();
Init();
}
错误/ s:
错误29以下方法或属性之间的调用不明确:'RssNews.FeederControl.InitializeComponent()'和'RssNews.FeederControl.InitializeComponent()'
然后在UserControl的设计者中:
错误31'RssNews.FeederControl.components'和'RssNews.FeederControl.components'之间的歧义
这是设计师代码:
namespace RssNews
{
partial class FeederControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// FeederControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.AntiqueWhite;
this.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.Name = "FeederControl";
this.Size = new System.Drawing.Size(146, 146);
this.Load += new System.EventHandler(this.FeederControl_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Timer timer1;
}
}
我在designer.cs代码中的所有组件上得到erorrs错误meassage。 并且
错误2类型'RssNews.FeederControl'已经定义了一个名为'InitializeComponent'的成员,其成员具有相同的参数类型
这个控件在我做同样代码的另一个项目上运行良好。 我刚刚更改了这个项目的名称空间名称。 之前的一个是mws,这个是RssNews
我该如何修复错误?
第一件事:你有一个不同的构造函数名称,然后是类名。 其次,你试过调试吗? 你张贴了太多的代码。 将其修改为相关部分。
解:
你有2个部分合并为一个,而函数InitializeComponent()定义了两次。 您必须仅在两个部分之一中定义它。 把它放在VS放的地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.