Rui Ruivo

Rui Ruivo

  • 1.5k
  • 132
  • 35.5k

How to iterate throw a list of object Forms ?

Oct 31 2021 3:30 PM

Hi everyone

I have this code that i want to simplify:

 // SETUP - Form Dashboard            objFormDashboard.TopLevel = false;pnlMainContainer.Controls.Add(objFormDashboard);objFormDashboard.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;objFormDashboard.Dock = DockStyle.Fill;objFormDashboard.Show();// SETUP - Form Database            objFormDatabase.TopLevel = false;pnlMainContainer.Controls.Add(objFormDatabase);objFormDatabase.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;objFormDatabase.Dock = DockStyle.Fill;objFormDatabase.Hide();// SETUP - Form UserProfile            objFormUserProfile.TopLevel = false;pnlMainContainer.Controls.Add(objFormUserProfile);objFormUserProfile.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;objFormUserProfile.Dock = DockStyle.Fill;objFormUserProfile.Hide();// SETUP - Form UserLogin           objFormUserLogin.TopLevel = false;pnlMainContainer.Controls.Add(objFormUserLogin);objFormUserLogin.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;objFormUserLogin.Dock = DockStyle.Fill;objFormUserLogin.Hide();// SETUP - Form UserRegisterobjFormUserRegister.TopLevel = false;pnlMainContainer.Controls.Add(objFormUserRegister);objFormUserRegister.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;objFormUserRegister.Dock = DockStyle.Fill;objFormUserRegister.Hide();

I am trying something like this:
 

          foreach (var item in listOfObjectForms){item.TopLevel = false;pnlMainContainer.Controls.Add(item);item.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;item.Dock = DockStyle.Fill;item.Show();}


But obviously it doesnt work

Any idea please ?

 

Best regards

Thank You.


Answers (5)