Update the form and all her children

I am working on old code that someone wrote. In this case, a subclass of Windows.Forms.Form is created inside another main Windows.Forms.Form

 class MainForm : Windows.Forms.Form { m_subForm = null; /* Much more stuff */ private void createSubForm { m_subForm= new SubForm(); m_subForm.Text = ""; m_subForm.MdiParent = this; m_subForm.WindowState = FormWindowState.Maximized; m_subForm.ControlBox = false; m_subForm.Show(); // There is no comment in the code on why this is done: this.Height -= 1; this.Height += 1; } } 

These last two lines are puzzling to me. They are actually necessary because if they are omitted, the shape inside the main shape is cut off at the edges. Only after you manually scale the screen, the subformation is again inserted into the main form. If you try to replace the tag += -= with:

 this.Refresh(); 

but it does not do the trick. Apparently, this only updates the main form, but not the subform. How can I fix this without this ugly hack?

+4
source share
1 answer
  m_subForm.ControlBox = false; 

What is illegal for the MDI child form, it must have all the window decoration correctly. And in fact, it can be used as an MDI child; it is a window model based on allowing the user to minimize / restore / maximize child windows. The dates of the early 1990s, when monitors still had very low resolutions, so there simply weren’t a lot of screen real estate to display windows.

However, Winforms does not apply this MDI requirement. The height trick was hacked so that the window would draw correctly. It should be noticeable from the flicker that produces.

It makes no sense to specify MDI when you always show the child window as much as possible. You get exactly the same effect, minus the need to fight the MDI control panel by simply replacing the UserControl in and out of the form. Such a UserControl can also be a Form if you set the TopLevel property to false.

+1
source

All Articles