View Form in a Tablelayoutpring C#

Asked

Viewed 45 times

0

How do I open a form named frmOrcamentos within a TableLayoutPanel so-called tlpPrincipal.
Remembering that the form frmOcamentos will open in the TableLayoutPanel that is inside the form frmPrincipal after clicking the button btnOrcamentos.

  • puts your code...

  • 1

    I don’t have a code yet 'cause I don’t even know where to start.

1 answer

1

I found what I wanted to do.
Code:

public partial class frmPrincipal : Form
{
    private Form _objForm; // Variável classe form

    public frmPrincipal()
    {
        InitializeComponent();
    }

    private void tsbVendas_Click(object sender, EventArgs e)
    {
        _objForm?.Close(); // Verifica se a variável _objForm já está ocupada, se estiver ele fecha

        _objForm = new frmVendas
        {
            TopLevel = false, // Desconsidera hierarquia das classes para não gerar erro
            FormBorderStyle = FormBorderStyle.None, // Remove a borda do formulário
            Dock = DockStyle.Fill // Expande formulário em todo o Panel
        };

        pnlPrincipal.Controls.Add(_objForm); // Adiciona formulário ao Panel
        _objForm.Show(); // Abre o formulário
    }
}

Browser other questions tagged

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