伊莉討論區

標題: 關於C# [打印本頁]

作者: flyinsky5    時間: 2009-5-18 10:34 PM     標題: 關於C#

下面這段程式碼
總是出現了這個問題~

錯誤 2 型別 'Test.Form1' 已經定義了一個具有相同參數型別名為 'InitializeComponent' 的成員 C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Form1.cs 29 22 WindowsFormsApplication1

我的程式如下
幫我看看個問題吧..
我不知道如何解決

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace Test
{
    public partial  class Form1 : Form
    {
        public Form1()
        {
            this.InitializeComponent();
            List<Video> videos = new List<Video>();
            this.bindingSource1.DataSource = videos;
            this.dataGridView1.DataSource = this.bindingSource1;
            this.dataGridView1.AutoGenerateColumns = true;
        }
        private BindingSource bindingSource1;
        private System.ComponentModel.IContainer components;
        private DataGridView dataGridView1;
        private ToolStrip toolStrip1;
        private ToolStripButton toolStripButton1;
        private ToolStripButton toolStripButton2;
        private ToolStripButton toolStripButton3;
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.bindingSource1 = new System.Windows.Forms.BindingSource(this.components);
            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            this.toolStrip1 = new System.Windows.Forms.ToolStrip();
            this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
            this.toolStripButton2 = new System.Windows.Forms.ToolStripButton();
            this.toolStripButton3 = new System.Windows.Forms.ToolStripButton();
            ((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            this.toolStrip1.SuspendLayout();
            this.SuspendLayout();
            //
            // dataGridView1
            //
            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.dataGridView1.Location = new System.Drawing.Point(0, 25);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.Size = new System.Drawing.Size(465, 343);
            this.dataGridView1.TabIndex = 1;
            //
            // toolStrip1
            //
            this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripButton1,
this.toolStripButton2,
this.toolStripButton3});
            this.toolStrip1.Location = new System.Drawing.Point(0, 0);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.Size = new System.Drawing.Size(465, 25);
            this.toolStrip1.TabIndex = 2;
            this.toolStrip1.Text = "toolStrip1";
            //
            // toolStripButton1
            //
            this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image")));
            this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButton1.Name = "toolStripButton1";
            this.toolStripButton1.Size = new System.Drawing.Size(51, 22);
            this.toolStripButton1.Text = "增加";
            this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click);
            //
            // toolStripButton2
            //
            this.toolStripButton2.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton2.Image")));
            this.toolStripButton2.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButton2.Name = "toolStripButton2";
            this.toolStripButton2.Size = new System.Drawing.Size(51, 22);
            this.toolStripButton2.Text = "刪除";
            this.toolStripButton2.Click += new System.EventHandler(this.toolStripButton2_Click);
            //
            // toolStripButton3
            //
            this.toolStripButton3.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton3.Image")));
            this.toolStripButton3.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButton3.Name = "toolStripButton3";
            this.toolStripButton3.Size = new System.Drawing.Size(51, 22);
            this.toolStripButton3.Text = "播放";
            //
            // Form1
            //
            this.ClientSize = new System.Drawing.Size(465, 368);
            this.Controls.Add(this.dataGridView1);
            this.Controls.Add(this.toolStrip1);
            this.Name = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();
        }
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            this.bindingSource1.AddNew();
        }
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            this.bindingSource1.RemoveCurrent();
        }
      }
    [Serializable]
    public class Video
    {
        private string _videoName;
        public string VideoName
        {
            get
            {
                return this._videoName;
            }
            set
            {
                this._videoName = value;
            }
        }
        private string _path;

        /// <summary>
        /// 可以是存在硬碟裡影片檔,也可以是網路節目URL
        /// </summary>
        public string Path
        {
            get
            {
                return this._path;
            }
            set
            {
                this._path = value;
            }
        }
    }

    public class Form3 : Form
    {
        public Form3()
        {
            this.InitializeComponent();
        }
        public Form3(string path)
            : this()
        {
            this.axWindowsMediaPlayer1.URL = path;
        }
        private AxWMPLib.AxWindowsMediaPlayer axWindowsMediaPlayer1;
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form3));
            this.axWindowsMediaPlayer1 = new AxWMPLib.AxWindowsMediaPlayer();
            ((System.ComponentModel.ISupportInitialize)(this.axWindowsMediaPlayer1)).BeginInit();
            this.SuspendLayout();
            //
            // axWindowsMediaPlayer1
            //
            this.axWindowsMediaPlayer1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.axWindowsMediaPlayer1.Enabled = true;
            this.axWindowsMediaPlayer1.Location = new System.Drawing.Point(0, 0);
            this.axWindowsMediaPlayer1.Name = "axWindowsMediaPlayer1";
            this.axWindowsMediaPlayer1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWindowsMediaPlayer1.OcxState")));
            this.axWindowsMediaPlayer1.Size = new System.Drawing.Size(506, 390);
            this.axWindowsMediaPlayer1.TabIndex = 0;
            //
            // Form3
            //
            this.ClientSize = new System.Drawing.Size(506, 390);
            this.Controls.Add(this.axWindowsMediaPlayer1);
            this.Name = "Form3";
            ((System.ComponentModel.ISupportInitialize)(this.axWindowsMediaPlayer1)).EndInit();
            this.ResumeLayout(false);
        }
    }

}




歡迎光臨 伊莉討論區 (http://a401.file-static.com/) Powered by Discuz!