Layout of invisible SplitContainer rearrange when become visible only

32 Views Asked by At

I want to restore a saved layout of a Windows Form. It contains a SplitContainer and I would also like to restore the SplitterDistance. That all doesn't look nice if I do it while the Form is visible. Therefore I tried to set the SplitContainer.visible to false, process the settings for the form and restore visible to false. But the effect is, that the SplitContainer performs size change not before it becomes visible and then it adapts the SplitterDistance automatically to another value. Neither PerformAutoScale() nor PerformLayout() help with that after changing the size before setting the SplitterDistance. How to resolve this in best way?

  splitContainer1.Visible = false;
  FormSetMode(xxx); // sets the layout of the form
  splitContainer1.ParentForm.PerformAutoScale();
  splitContainer1.ParentForm.PerformLayout();
  splitContainer1.SplitterDistance = SplitterPosition;
  SetSplitter(fHorizontalDesigner);  // sets the splitter orientation with automatic adaption of the SplitterDistance when orientation changes
  splitContainer1.Visible = true;

PerformAutoScale and PerformLayout don't work if they are related to splitContainer1 directly instead of using splitContainer1.ParentForm.

0

There are 0 best solutions below