Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5997323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:14:50+00:00 2026-05-23T00:14:50+00:00

I currently have two different event handlers in C#, which perform two different functions.

  • 0

I currently have two different event handlers in C#, which perform two different functions. Although how could I combine the two methods together, so only 1 button could perform both actions? (Taking into account that button1_Click event must be performed first.)

    private void button2_Click(object sender, EventArgs e)
    {
        var file = File.AppendText(@"c:\output2.txt");

        foreach (string tmpLine in File.ReadAllLines(@"c:\output.txt"))
        {
            if (File.Exists(tmpLine))
            {
                file.WriteLine(tmpLine);
            }
        }

        file.Close();

    }

    private void button1_Click(object sender, EventArgs e)
    {
        using (StreamWriter sw = File.AppendText(@"c:\output.txt"))
        {
            StreamReader sr = new StreamReader(@"c:\filename.txt");

            string myString = "";
            while (!sr.EndOfStream)
            {

                myString = sr.ReadLine();
                int index = myString.LastIndexOf(":");
                if (index > 0)
                    myString = myString.Substring(0, index);

                sw.WriteLine(myString);
            }
            button2_Click(sender, e);

        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:14:50+00:00Added an answer on May 23, 2026 at 12:14 am

    Instead of writing the code in the event handler, bring them out into two functions and then call those functions whichever way you want from the event handler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have two text boxes which accept any number. I have a text
All, I currently have two projects that are under SourceSafe that I am unable
Currently I have two MediaWikis, one a slightly older version than the other. I
I currently have an asp.net website hosted on two web servers that sit behind
I have an Auction model with several attributes, two of which are current_auction:boolean and
I have a web service with two methods: RetrieveFirstLevelOptions() and RetrieveSecondLevelOptions(int levelOneOption). The GUI
I have a Google Map, and I am adding event listeners to different things.
I have the following two methods on an interface for my service layer: ICollection<T>
I am currently writing an utility that takes two different sets of data from
I have an interesting situation - I have a table row which, currently, shows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.