cs0111(类型'表单1'已定义成员'初始化组件')

时间:2017-12-12 15:05:05

标签: c#

我需要帮助,这是我的代码:

    /*
     * Created by Gary Perkin.
     * Date: 02/11/2004
     * Time: 14:30
     * 
     */
 
    using System;
    using System.Windows.Forms;
    using System.Threading;
 
    namespace DefaultNamespace
    {
    /// <summary>
    /// Demo application for vuMeterLED  -perhaps not the most elegant design in the world,
    /// but it gets the job done.   
    /// </summary>
    public partial class Form1 : System.Windows.Forms.Form
    {
        private Gary.Perkin.UserControls.vuMeterLED vuMeterLED2;
        private Gary.Perkin.UserControls.vuMeterLED vuMeterLED3;
        private Gary.Perkin.UserControls.vuMeterLED vuMeterLED4;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Timer timer1;
        private Gary.Perkin.UserControls.vuMeterLED vuMeterLED1;
 
        int cycleCount;
        Random r = new Random();
 
        [STAThread]
        public static void Main(string[] args)
        {
            Application.Run(new Form1());
        }
 
        #region Windows Forms Designer generated code
        /// <summary>
        /// This method is required for Windows Forms designer support.
        /// Do not change the method contents inside the source code editor. The Forms designer might
        /// not be able to load this method if it was changed manually.
        /// </summary>
        public void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.vuMeterLED1 = new Gary.Perkin.UserControls.vuMeterLED();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.vuMeterLED4 = new Gary.Perkin.UserControls.vuMeterLED();
            this.vuMeterLED3 = new Gary.Perkin.UserControls.vuMeterLED();
            this.vuMeterLED2 = new Gary.Perkin.UserControls.vuMeterLED();
            this.SuspendLayout();
            // 
            // vuMeterLED1
            // 
            vuMeterLED1.Location = new System.Drawing.Point(40, 72);
            vuMeterLED1.Name = "vuMeterLED1";
            vuMeterLED1.Size = new System.Drawing.Size(16, 123);
            vuMeterLED1.TabIndex = 5;
            vuMeterLED1.Volume = 0;
            // 
            // timer1
            // 
            this.timer1.Enabled = true;
            this.timer1.Interval = 500;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(24, 16);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(56, 23);
            this.button1.TabIndex = 1;
            this.button1.Text = "Start";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(88, 16);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(56, 23);
            this.button2.TabIndex = 4;
            this.button2.Text = "Stop";
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // vuMeterLED4
            // 
            this.vuMeterLED4.Location = new System.Drawing.Point(112, 72);
            this.vuMeterLED4.Name = "vuMeterLED4";
            this.vuMeterLED4.Size = new System.Drawing.Size(16, 123);
            this.vuMeterLED4.TabIndex = 8;
            this.vuMeterLED4.Volume = 0;
            // 
            // vuMeterLED3
            // 
            this.vuMeterLED3.Location = new System.Drawing.Point(88, 72);
            this.vuMeterLED3.Name = "vuMeterLED3";
            this.vuMeterLED3.Size = new System.Drawing.Size(16, 123);
            this.vuMeterLED3.TabIndex = 7;
            this.vuMeterLED3.Volume = 0;
            // 
            // vuMeterLED2
            // 
            this.vuMeterLED2.Location = new System.Drawing.Point(64, 72);
            this.vuMeterLED2.Name = "vuMeterLED2";
            this.vuMeterLED2.Size = new System.Drawing.Size(16, 123);
            this.vuMeterLED2.TabIndex = 6;
            this.vuMeterLED2.Volume = 0;
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(184, 245);
            Controls.Add(vuMeterLED4);
            this.Controls.Add(vuMeterLED3);
            this.Controls.Add(vuMeterLED2);
            this.Controls.Add(vuMeterLED1);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Opacity = 0.99;
            this.Text = "vuMeterLED Demo";
            this.ResumeLayout(false);
        }
        #endregion
 
        // Activate each LED in turn, at about 120bpm (500 msec per tick)
        private void timer1_Tick(object sender, System.EventArgs e)
        {
            cycleCount++;
            LightLEDs(cycleCount);
 
            if (cycleCount == 4) cycleCount = 0;
 
        }
 
        // Light each LED in turn, depending which "beat" we're on
        private void LightLEDs(int count)
        {
            int sleepLength = 100;                      // Controls speed at which levels decay
            int rSeed = 15;                             // Range for random number generator
 
            if (count == 1)
            {
                for (int j = 5 + (r.Next(rSeed)); j >= 0; j--)
                {
                    vuMeterLED1.Volume = j;
                    vuMeterLED1.Refresh();
                    Thread.Sleep(sleepLength / (j + 1));    // Make the LEDs "bounce"
                }
            }
 
            if (count == 2)
            {
                for (int j = 5 + (r.Next(rSeed)); j >= 0; j--)
                {
                    vuMeterLED2.Volume = j;
                    vuMeterLED2.Refresh();
                    Thread.Sleep(sleepLength / (j + 1));    // Make the LEDs "bounce"
                }
            }
 
            if (count == 3)
            {
                for (int j = 5 + (r.Next(rSeed)); j >= 0; j--)
                {
                    vuMeterLED3.Volume = j;
                    vuMeterLED3.Refresh();
                    Thread.Sleep(sleepLength / (j + 1));    // Make the LEDs "bounce"
                }
            }
 
            if (count == 4)
            {
                for (int j = 5 + (r.Next(rSeed)); j >= 0; j--)
                {
                    vuMeterLED4.Volume = j;
                    vuMeterLED4.Refresh();
                    Thread.Sleep(sleepLength / (j + 1));    // Make the LEDs "bounce"
                }
            }
 
        }
 
        private void button1_Click(object sender, System.EventArgs e)
        {
            timer1.Start();
        }
 
        private void button2_Click(object sender, System.EventArgs e)
        {
            timer1.Stop();
        }
 
    }
}

我不断收到错误cs0111(类型'表单1'已定义成员'初始化组件') 这很有趣,因为我刚刚摆脱了这一行来修复cs0121(以下方法或属性之间的调用不明确:' form1.InitializeComponent' form1.InitializeComponent' )

public Form1()
{
    InitializeComponent();
}

是的,有一个设计师使用此代码

using System.Windows.Forms;

namespace DefaultNamespace
{
partial class Form1
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    public new AutoScaleMode AutoScaleMode { get; private set; }
#pragma warning disable CS0114 // Member hides inherited member; missing override keyword
    public string Text { get; private set; }
#pragma warning restore CS0114 // Member hides inherited member; missing override keyword

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    #region Windows Form 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()
    {
        components = new System.ComponentModel.Container();
        AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        Text = "Form1";
    }
    #endregion
}
}

0 个答案:

没有答案