2014-01-26 32 views
0

我有這樣的用戶控件,我創建和Im上InitializeComponent爲什麼即時通訊錯誤在行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(); 
     } 

得到錯誤的錯誤/秒:

錯誤29的呼叫是以下方法或 屬性之間曖昧:「RssNews。 FeederControl.InitializeComponent()」和 'RssNews.FeederControl.InitializeComponent()'

然後在UserCon設計師特倫:

錯誤 'RssNews.FeederControl.components' 和 之間31歧義 '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; 
    } 
} 

即時得到erorrs designer.cs代碼中所有組件上的相同錯誤消息。 而且還

錯誤類型2「RssNews.FeederControl」已經定義了一個名爲成員 「的InitializeComponent」具有相同的參數類型

這種控制是很好的工作在另一個項目中,我做了相同的代碼。我只是改變了這個項目的命名空間名稱。前一個是mws,這是RssNews

我該如何解決這些錯誤?

+2

聽起來像你有* two * Designer.cs UserControl的源文件。很難猜測你是如何做到的:)刪除其中的一個。在構造函數中不調用InitializeComponent()是你會後悔的另一件事情,它不會在設計器中運行良好。 –

回答

2

首先,您有不同的構造函數名稱,然後是類名稱。 二,你有沒有試過調試它?你發佈的代碼太多了。 修剪它的相關部分。

解決方案:

你有2名諧音被合併成一個,函數的InitializeComponent()定義了兩次。您只能在兩個部分之一中定義它。把它放在VS放置的地方。

相關問題