Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2015-02-12
6
101 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 34

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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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