Changing content of one form without opening another in c#

Asked

Viewed 542 times

-3

I would like to know, how do I change the content of the Form without opening another, when I click Encryption for example, the content changes without opening another Form. How do I do that?

Form

  • you can use a tabControl, or open the other Forms within that main

1 answer

1


Manipulating UserControl(s) you can create an inherited object from Control. So, create your form in this UserControl and make it work as a Form.

After that, create a Panel client who will display the pages, and declare the controls as in the example below:

public UserControlHome ucHome = new UserControlHome();
public UserControlCripto ucCripto = new UserControlCripto();

And create this method to change the Control who is in the Panel client conteudo:

public void AlterarConteudo(ref Control controle) {
    // considere 'conteudo' o Panel que irá ter os controles dentro
    conteudo.Controls.Clear(); // - remove os controles dentro do Panel
    { // altera propriedades do controle que irá ser colocado
        controle.Dock = DockStyle.Fill;
    }
    // adiciona o controle ao cliente
    conteudo.Controls.Add(controle);
}

And when you click the Encryption button, call the method with the expression:

AlterarConteudo(ref ucCripto);

And to the Home button:

AlterarConteudo(ref ucHome);

Remember to implement a method to save information to the controls while being discarded.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.