How to call eventhandler from other event handler?


Sometimes you need to call events of two or more controls on your form together with single click of one control. Here you can do this.

How to Call EventHandler From Other EventHandler



I faced a problem to call eventhandler of First control from the eventhandler of the other Second control. So I just called the eventhandler of first control by declaring code in second control.

For example: I am calling Reset button event handler from Submit button event handler. And it work nice!

Code Snippet:



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

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

private void btnSubmit_Click(object sender, EventArgs e)
{
lblSubmitMessage.Text = "Submit Message: Submit button clicked!";

//Calling other event handler
btnReset_Click(this, EventArgs.Empty);

}

private void btnReset_Click(object sender, EventArgs e)
{
txtValue.Text = String.Empty;
lblResetMessage.Text = "Reset Message: Reset button clicked!";
}
}
}


Attachments

  • eventhandler (37634-11438-dns_EventsFromMethods.rar)
  • Comments

    No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: