WinForms Held Controls Do Not Maximize Validity

I have a problem with WinForms (VB.NET).

The main window is the MDI container. The user opens a new child window:

non maximized child 1

and then maximizes it, so the window fills the client area correctly. My controls are properly tied (using the Anchor IDE property) to the sides of the window, so that enlarging the window always fills the client area well:

maximized child 1

In this state (client windows are enlarged), the user opens another or new child window, but the new window controls are not stretched, that is, they do not "understand" that they must be stretched!

non stretched child 2

This is especially annoying because if the user tries to restore the window, then the controls are stretched, so they disappear (see no more list)!

restored child 2

This is mistake? How can i solve this?

edit: according to Hans Passant's comment, I created a new simple project and it worked as it should. Therefore, I researched what distinguishes my real project and sample. The difference is that in my project I dynamically create forms.

I am dynamically creating many toolbar buttons. When the user clicks the button, this is the code that is executed:

Private Sub buttonClicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Cursor.Current = Cursors.WaitCursor Dim b As Button = CType(sender, Button) Dim assem As Assembly = Assembly.GetExecutingAssembly() Dim formType As Type = assem.GetType(CStr(b.Tag)) Dim exFormAsObj As Object = Nothing Try exFormAsObj = Activator.CreateInstance(formType) Catch ex As Exception Cursor.Current = Cursors.Default MessageBox.Show("clicca meglio:" + ex.ToString) Exit Sub End Try Dim f As Form = CType(exFormAsObj, Form) f.MdiParent = Me f.Show() Cursor.Current = Cursors.Default End Sub 

That is, the form name is in the button tag. I create a new instance of the form, with Activator.CreateInstance(formType) , then I will show it: f.Show() .

I am sure the problem is creating this dynamic child form, but I cannot get there.

edit2: Found! In my form, the general loading event that I was doing

 myform.SuspendLayout() ' various instructions myform.ResumeLayout(False) 

instead of False, I would have to write true: myform.ResumeLayout(True)

So simple, sorry.

+8
controls winforms
source share
4 answers

I found a solution (thanks to Cody Gray, suggesting posting my own answer here).

In my form, the usual load event that I did:

 myform.SuspendLayout() '' various instructions myform.ResumeLayout(False) 

instead of False I should have written true : myform.ResumeLayout(True)

Simple but complex. Thanks to everyone.

+3
source share

I think that what you might want to achieve is done with

 this.LayoutMdi(MdiLayout.TileHorizontal); 

or one of his relatives.

Keep in mind that MDI layouts are generally discouraged.

+1
source share

My controls are properly bound (using the Anchor IDE property)

Perhaps try setting the form and setting the program properties in the load event.

If one instance works, but other instances do not, it means that you need to check the properties of the inline forms with a debugger to make sure that they are actually set as you expect.

0
source share

I used datagridview in the mdi child form with all four sides attached, and it will scale correctly until the form was created not maximized. If I created the form at a time when other children were maximized, it was incorrect and never corrected, even if you normalized and resized the form manually. My solution was to place the panel on the form with all four sides fixed and placing the DGV in the panel with the dock installed. I have no idea why I should have done this, but this fixed the problem.

0
source share

All Articles