为什么我在行InitializeComponent();?

时间:2014-01-26 23:48:20

标签: c# winforms

我有这个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代码中的所有组件上获得了相同的错误消息。 而且

  

错误2类型'RssNews.FeederControl'已经定义了一个名为的成员   'InitializeComponent'具有相同的参数类型

这个控件在我做同样代码的另一个项目上运行良好。我刚刚更改了这个项目的名称空间名称。之前的一个是mws,这个是RssNews

如何解决错误?

1 个答案:

答案 0 :(得分:2)

首先:你有一个不同的构造函数名,然后是类名。 其次,你试过调试吗?你张贴了太多的代码。 将其修改为相关部分。

解决方案:

你有2个部分被合并为一个,而函数InitializeComponent()定义了两次。您必须仅在两个部分之一中定义它。把它放在VS放的地方。