I'm having trouble displaying one form inside another through a panel.
The issue is that by modifying the state of the main form from WindowState == FormWindowState.Normal
to WindowState == FormWindowState.Maximized
, the form opened in the panel does not follow the size of the main form, thus:
Normal form:
Maximizedform:
Anotherproblemisthatwhenpassingthemainformfromnormaltomaximizedwithsomeformopeninthepanel,themainformdoesnotfilltheentirescreen,thus:
Code used to open forms in the panel:
public void AbrirFormulario(Type formType)
{
pnFormulários.Enabled = true;
pnFormulários.Visible = true;
this.SuspendLayout();
if (btVoltarInicio.Enabled == false)
{
try
{
for (int i = 0; i < lstFormulario.Count; i++)
{
lstFormulario[i].Close();
lstFormulario[i].Dispose();
lstFormulario[i] = null;
}
lstFormulario.Clear();
Form form = (Form)Activator.CreateInstance(formType);
form.WindowState = FormWindowState.Maximized;
form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
form.TopLevel = false;
pnFormulários.Controls.Add(form);
form.Show();
lstFormulario.Add(form);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
this.ResumeLayout(true);
btVoltarInicio.Enabled = true;
btVoltarInicio.Visible = true;
}
else
{
}
}
Button to open some form:
private void btCadCategorias_Click(object sender, EventArgs e)
{
AbrirFormulario(typeof(cadastro_categoria));
}