1
Hello,
I have a problem to pass information between windows forms Forms with C#, the problem is as follows. I have a MAIN FORM, from this I call the a SUB FORM, which happens to be the son of the principal. The point is, I want SUB FORM to give me, or return information back to MAIN. It can be a boolean value, list, anyway, I want to pass any value.
Example:
IN THE MAIN FORM:
private void buttonDiretorio_Click(object sender, EventArgs e)
{
Form Frm = new FormOpenDirectorySystem();
Frm.ShowDialog();
bypass = Frm.bypass;
if (bypass)
{
MessageBox.Show("O acesso foi concedido.", "Acesso liberado.", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (Directory.Exists("C:\\Diretorio\\"))
{
//abro o diretório
}
else MessageBox.Show("O diretório raiz do sistema não foi encontrado.", "Problema ao abrir o diretório raiz", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
IN THE SUBFORM THAT IS CALLED BY THE MAIN FORM:
public partial class FormOpenDirectorySystem : Form
{
public FormOpenDirectorySystem()
{
InitializeComponent();
}
public bool bypass = false;
private void buttonCancelar_Click(object sender, EventArgs e)
{
bypass = false;
this.Close();
}
private void buttonContinuar_Click(object sender, EventArgs e)
{
String password = txtBypass.Text;
if (password == "1q2w3e4r5t")
{
bypass = true;
this.Close();
}
else
{
bypass = false;
this.Close();
}
}
}
In this example, I am in the main form, and I call a new screen, where I will read a password/password/bypass, and I want this bypass to return TRUE, if "authentication" was successful, or FALSE if it was unsuccessful.
Sincerely yours;
You probably want some of this one: http://answall.com/search?q=%5Bc%23%5D+entre+Forms
– Maniero
@bigown I was really looking for a dup for this, but it seems like everyone wants to do the opposite.
– Jéf Bueno
John, I wrote an answer and now I realize what you do exactly that in the question code! What is the problem with the current code?
– Jéf Bueno
the problem is exactly that it does not work, kk What would be the error in the code because I am trying with this method and just have no return of anything.
– João Regis
Doesn’t work like? Be clearer! What happens? Does it make a mistake? The return is always the same?
– Jéf Bueno
Good,. in the sample code I try to access the property of my SUB FORM, frm.bypass, and step it to bypass , in my main form.
– João Regis
It turns out that in the main form, I have the error that there is no "bypass" property in "frm".
– João Regis