I have two forms.When i click a button in Fomr1 after pasting encryption code in textbox,it loads Form2 with asking password and when i click Ok it should close Form2 and it should call a method from From1 without refreshing Form1(Because am doing decryption in Form1 and if i use new Form1(); it Reloads the Form1 and decryption is not working). Below is my code:
public partial class Form2 : Form
{
private Form1 form1;
Form2 form2;
public Form2()
{
InitializeComponent();
}
public bool CheckPwd()
{
if (textBox1.Text == "Hi")
return true;
else
return false;
}
private void ok_Click(object sender, EventArgs e)
{
form2 = new Form2();
//form1 = c
if (!CheckPwd())
{
MessageBox.Show("Password is Incorrect", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
form2.ShowDialog();
form1.Hide();
return;
}
else
{
MessageBox.Show("Password ok", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
form1.Decrypting();
}
}
In form1.Decrypting(); i am getting the error "Object reference not set to instance of an object".