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

  • SEARCH
  • Home
  • 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 have an interesting situation - I have a table row which, currently, shows
I am using WPF with model-view-viewmodel pattern. I have a ResultsView and ResultsViewModel which
Summary I have a large an rapidly changing dataset which I wish to bind
I have two links inside a div called div A. when link 1 is
Scenario : In a Silverlight 4 MVVM project, we have a ListBox control containing
So I have been trying to figure out the best way to go about
I'm using a ViewSwitcher that lets me easily flip back and forth between two
Right now my goal is to have anti-aliased text on my Labels. If my
I'm using the SimpleModal plugin to display a dialog on a site. Within that
We are builing a windows desktop application (not web based) and trying to come

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.