Solved

Why source code for first button affect source code of the other button ?

Posted on 2015-02-12
6
99 Views
Last Modified: 2015-02-18
I am writing my first C# Program in Microsoft Visual C# 2010 Express.  From "New Project" window, I select "Visual C#", "Windows Forms Application".  I create two buttons.  When I write the source code for first button, it propagates to source code of second button.  

Why ?

I need both button's source code to be independent of each other.
0
Comment
Question by:naseeam
6 Comments
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40606958
Could you post the code you have?

By propagate, do you mean to say that you change first code for the first button and the code for the 2nd button changes by itself?

Mike
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40607136
Hi naseeam;

In order to answer a question like this on we would need to see the code, can you please post it.

Thanks;
Fernando
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 40607153
Very, very strange... Try to clean the solution before editing and  building it...
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 40607314
Perhaps you had both buttons selected at the same time (by holding down the shift key when clicking on them) and then you assigned a handler to the Click() event using the lightning bolt icon in the Properties Pane?  This would assign the same click handler to all currently selected buttons.
0
 
LVL 1

Accepted Solution

by:
naseeam earned 0 total points
ID: 40607825
Yes, I thought changing code for the first button changes code for the second button.  But there is only one source code file for both buttons.

I tried to clean solution before editing and building because I thought there are separate source code files for each button.  But there is only one source code for both button.

Everything is working fine.  Thanks for everyone's help.




/* Source code after double-clicking Button1 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SimpleProgram
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}

Open in new window



/* I wrote body of following function */

 private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("You clicked on the Red Button", "Red Button");
        }

Open in new window



/* Following is code after double-clicking second button */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SimpleProgram
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("You clicked on the Red Button", "Red Button");
        }

        private void button2_Click(object sender, EventArgs e)
        {

        }
    }
}

Open in new window



/* I wrote body of following function */

private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("You clicked on the Blue Button", "Blue Button");
        }
0
 
LVL 1

Author Closing Comment

by:naseeam
ID: 40616140
I found the problem myself.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question