I'm working on a WinForms application in C# and facing an issue with a button's visibility. My application has a main form MainForm which opens other forms as child forms inside a panel. One of these child forms is UserForm, which contains a button btnAdd.
When I run UserForm independently, everything works fine and btnAdd is visible and functional. However, when I open UserForm as a child form within MainForm's panel, btnAdd becomes invisible or inaccessible.
Here's how I'm opening child forms in MainForm:
private void openChildForm(Form childForm)
{
if (activeForm != null)
activeForm.Close();
activeForm = childForm;
childForm.TopLevel = false;
childForm.FormBorderStyle = FormBorderStyle.None;
childForm.Dock = DockStyle.Fill;
panelMain.Controls.Add(childForm);
panelMain.Tag = childForm;
childForm.BringToFront();
childForm.Show();
}
And here's the btnAdd_Click event in UserForm:
private void btnAdd_Click(object sender, EventArgs e)
{
UserModuleForm userModule = new UserModuleForm();
userModule.btnSave.Enabled = true;
userModule.btnClear.Enabled = false;
userModule.ShowDialog();
LoadUser();
}
I've tried the following:
- Checked the
btnAddproperties (Visible is set to True). - Made sure
btnAddis not being overlapped by other controls. - Used breakpoints to see if something is changing
btnAdd's visibility state.
I suspect the issue might be related to how the form is being docked or displayed in the panel, but I'm not sure how to fix it. Any suggestions on what might be causing this and how to resolve it would be greatly appreciated.