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)