Can someone help me fix my code, it doesnt open usercoontrols form porperly
i just satrted to learn c# and if i dont understand something sorry


$codegif in chat$codeprivate void guna2Button8_Click(object sender, EventArgs e)
{
// Create the UC_ListBoxhub user control and pass the Form1 reference to it
UC_ListBoxhub uc = new UC_ListBoxhub(this); // Passing reference to Form1
addUserControl(uc); // Add the user control
}
private void addUserControl(UserControl userControl)
{
// Loop through controls and hide any other user control (but keep FastColoredTextBox visible)
foreach (Control ctrl in this.Controls)
{
if (ctrl is UserControl && ctrl != userControl) // Hide other user controls
{
ctrl.Hide();
}
}
// If the user control is not already added, add it
if (!this.Controls.Contains(userControl))
{
userControl.Dock = DockStyle.Fill; // Make sure it fills the form
Controls.Add(userControl); // Add the user control
}
userControl.BringToFront(); // Bring the new user control to the front
}