Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to call previous form method in window application C#

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 159
    Comment on it

    Sometime there is a situation where we have to call previous page method after completing the current page process. This is usually required when we open the page in Dialog box.
    Here below is the example of this.In this example, I open the 2nd form in Dialog box and if user click cancel button then print message the first form.

    Form1:

    public partial class Form1 : Form
    {
    	public Form1()
    	{
    		InitializeComponent();
    	}
    	public void btnForm2_Click(object sender, EventArgs e)
    	{
    		Form2 form2 = new Form2();
    		form2.form1 = this;
            form2.ShowDialog();
    	}
    	public void ShowMessage()
    	{
    	  label1.Text="Second form process is cancelled.";
    	}
    }

    Form2:

    public partial class Form2 : Form
    {
        public Form1 form1;
    	public Form2()
    	{
    		InitializeComponent();
    	}
    	private void buttonCancel_Click(object sender, EventArgs e)
    	{
    		if (form1 != null)
                {
    			   this.Hide();
                   form1.ShowMessage();
                }
    	}
    }

    Hope this will help you. Thanks

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: