Click here to Skip to main content
16,017,922 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i need help her is my code
/*
 * 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();
        }

    }
}

i keep getting the error
cs0111(type 'form 1' already defines a member'initialize component')


What I have tried:

it's funny because i just got rid of this line to fix cs0121
public Form1()
{
    InitializeComponent();
}
Posted
Updated 8-Dec-17 5:35am
Comments
Richard Deeming 8-Dec-17 11:24am    
That's a partial class, so there's probably another part somewhere. Most likely nested under the main file, with a ".designer" in the filename.

You'll find that you have a method called InitializeComponent in both parts.

1 solution

Look at the date on that file: 20/11/2004 - that means it was V1.0 of C#, and Visual Studio 2005.

The way VS handles projects has changed since then: all the designer based code is in a separate, almost-hidden-but-not-quite file called NameOfForm.designer.cs and when you create a new project that is created for you. That file contains the designer code including InitalizeComponent which creates all the controls on the form.

What you did was create a new project, and copy the old file code directly in. As a result, you get two methods with the same name. Check them carefully to make sure you have all the required controls and variable definitions before you delete either!
 
Share this answer
 
Comments
Member 13525065 12-Dec-17 9:50am    
yeah but i'm using visual studio 2015
OriginalGriff 12-Dec-17 9:55am    
Yes. But that means when you create a file in VS2015, you can't just throw the source code from a VS 2005 version project in there -you have to intelligently add the right bits to the right files.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900