How do I get Text from a TextBox on a Second Form and assign it to a String in the main form?

0

Class class class class value in String keySymmetric of class ACEcrypt. strong> But I do not know how to receive and cast: (

Form class to enter password.

public partial class Senha : Form
{

    string key;

    public Senha()
    {
        InitializeComponent();
    }

    private void btn_enviarKey_Click(object sender, EventArgs e)
    {
        key = textBoxKey.Text;
        this.Close();
    }
}

Main form class

public partial class ACEcrypt : Form
{

    string chaveSimetrica;

    public ACEcrypt()
    {
        InitializeComponent();
    }

    private void btn_criptografar_Click(object sender, EventArgs e)
    {
        if (openFileCrypt.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            exibirCaminho.Text = openFileCrypt.FileName;

            //Input do Arquivo ou Pasta
            string streamPath = exibirCaminho.Text;

            FileStream inStream = File.OpenRead(openFileCrypt.FileName);
            //FileStream outStream = File.OpenWrite(openFileCrypt.FileName + ".ace");
           // int b;

            //while ((b = inStream.ReadByte()) > -1)
            //    outStream.WriteByte((byte)b);

            //outStream.Flush();
            //outStream.Close();
            inStream.Close();

            Senha ISCrypt = new Senha();
            ISCrypt.ShowDialog();
            ISCrypt.FormClosing += new FormClosingEventHandler(ISCrypt_FormClosing);

            //Para teste
            //MessageBox.Show(chaveSimetrica);

        }
    }

    void ISCrypt_FormClosing(object sender, FormClosingEventArgs e)
    {
        if ((sender as Senha).textData != null)
            chaveSimetrica = (string)(sender as Senha).textData;

    }

    private void btn_descriptografar_Click(object sender, EventArgs e)
    {
        if (openFileDecrypt.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            exibirCaminho.Text = openFileDecrypt.FileName;

        }
    }
}
    
asked by anonymous 07.12.2015 / 10:28

1 answer

2

In form Senha , you can create a public property that returns the string key .

public string Key
{ 
    get{ return key;}
}

Then after ISCrypt.ShowDialog(); you would be able to access ISCrypt.Key;

Senha ISCrypt = new Senha();
ISCrypt.ShowDialog();
chaveSimetrica = ISCrypt.Key;
    
07.12.2015 / 13:56