Adding a control that has it's Dock
property set to DockStyle.Fill
outside of the form's InitializeComponent()
function doesn't consider the adjacent controls in the form.
In this case my DataGridView
control is being underlapped by my MenuStrip
control.
I assume it has something to do with SuspendLayout()
,ResumeLayout(false)
, and PerformLayout()
and I've tried mimicking the function calls done in InitializeComponent()
as so:
mainForm = new Form1();
//add post-init control
mainForm.menuStrip1.SuspendLayout();
mainForm.SuspendLayout();
mainForm.TableMainGridView = mainForm.GetGridView();
((System.ComponentModel.ISupportInitialize)(mainForm.TableMainGridView)).BeginInit();
mainForm.Controls.Add(mainForm.TableMainGridView);
((System.ComponentModel.ISupportInitialize)(mainForm.TableMainGridView)).EndInit();
mainForm.menuStrip1.ResumeLayout(false);
mainForm.menuStrip1.PerformLayout();
mainForm.ResumeLayout(false);
mainForm.PerformLayout();
But it doesn't change anything.
After some more digging it seems that SuspendLayout()
and ResumeLayout()
are only used for the performance of forms with many controls.
PerformLayout()
is supposed to "force the control to apply layout logic to all its child controls." but as to what this "layout logic" is remains a mystery to me.