✅ Swap between multiple forms on a single panel

Im currently working on this project and ive designed it so that my main form has a panel and on top are buttons that should load different forms If i open a form with a button when the panel is empty the form loads properly, no matter what form i open, but if a form is already loaded then it doesnt swap. Any ideas?
18 Replies
TheBoxyBear
TheBoxyBear3mo ago
$code
MODiX
MODiX3mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
UnawareModesty
UnawareModesty3mo ago
private void PeopleButton_Click(object sender, EventArgs e)
{
PeopleMainForm peopleMainForm = new PeopleMainForm() { TopLevel = false, TopMost = true };
peopleMainForm.FormBorderStyle = FormBorderStyle.None;
mainpanel.Controls.Add(peopleMainForm);
peopleMainForm.Show();


}

private void ProductsButton_Click(object sender, EventArgs e)
{
ProductVendorMainForm productVendorForm = new ProductVendorMainForm() { TopLevel = false, TopMost = true };
productVendorForm.FormBorderStyle = FormBorderStyle.None;
mainpanel.Controls.Add(productVendorForm);
productVendorForm.Show();
}
}
private void PeopleButton_Click(object sender, EventArgs e)
{
PeopleMainForm peopleMainForm = new PeopleMainForm() { TopLevel = false, TopMost = true };
peopleMainForm.FormBorderStyle = FormBorderStyle.None;
mainpanel.Controls.Add(peopleMainForm);
peopleMainForm.Show();


}

private void ProductsButton_Click(object sender, EventArgs e)
{
ProductVendorMainForm productVendorForm = new ProductVendorMainForm() { TopLevel = false, TopMost = true };
productVendorForm.FormBorderStyle = FormBorderStyle.None;
mainpanel.Controls.Add(productVendorForm);
productVendorForm.Show();
}
}
thats basically the 2 buttons that activate the forms on the panel(mainpanel) when i press any button to load a form on the panel it loads normally, but i havent figured out a way to be able to swap between forms
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
UnawareModesty
UnawareModesty3mo ago
ima be honest, im a beginner and this is the first way i found to make panels
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
UnawareModesty
UnawareModesty3mo ago
i mean, it means add lol
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
UnawareModesty
UnawareModesty3mo ago
the only thing i guess ive found is how to refresh the panel but when i load a different panel again it didnt work but its probably cause of the add thing?
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
UnawareModesty
UnawareModesty3mo ago
yeah i just saw there is remove after panel.controls lemme try i mean i get the logic with the remove, but now ive run into not knowing how to get the name of the form created by the button cause i cant do panel.controls.remove without a name only way im currently thinking about this rn is to make 2 panels that load at start and the only thing the buttons do is hide and unhide the respective panels
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
UnawareModesty
UnawareModesty3mo ago
nahh not really ill try to create different panels and we'll see how it looks
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
UnawareModesty
UnawareModesty3mo ago
ok so i tried this but when i overlap panels in the form design, every part of a panel that overlaps another panel hides aswell when i hide the panel i want gone
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
UnawareModesty
UnawareModesty3mo ago
ehhh ill try smth maybe tommorow ive already been coding for like 10 hours today lol thanks for the ideas and help anyway :peepohappy: