Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
Im trying to resize a form with code while using Application.OpenForms, but I know that I have missed something simple but I can't get it too work.

C#
foreach(Form frm in Application.OpenForms)
{
  System.Drawing.Size newSize = new System.Drawing.Size(500,500);
  frm.Size = newSize;

  //Have also tried
  frm.Width = 500;
  frm.Height = 500;
}


[EDIT]Sorry I forgot to say, each form that needs to be resized is a borderless form (with toplevel set to false) that is in a panel

[SOLVED] changed the loop to the Panels controls collection and it works. for example.

C#
foreach(Form frm in Panel2.Controls)
{
 System.Drawing.Size newSize = new System.Drawing.Size(500,500);
 frm.Size = newSize;
 frm.refresh();
}


Any help will be grateful

Thanks
Simon
Posted
Updated 26-Mar-12 4:53am
v4

1 solution

Try
 foreach(Form frm in Application.OpenForms)
 {
   System.Drawing.Size newSize = new System.Drawing.Size(500,500);
   frm.Size = newSize;
   frm.refresh;

 }
 
Share this answer
 
v2
Comments
Simon_Whale 26-Mar-12 10:50am    
Thanks Abhinav,

I found my problem - these forms where added to a panel which are also borderless, so instead of looping the openForms collection change it to the Panel.Controls it all of a sudden works I knew it was simple.

Thank you for your help :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900