Bohn
Bohn

Reputation: 26919

Why Cascading is also resizing the forms?

User opens a child form, resizes it a little bit, then opens another form, and I am calling

this.LayoutMdi(System.Windows.Forms.MdiLayout.Cascade);

when we are opening a child form. So yes it cascades them but also resizes them to some default size I do not know where it is getting it from. Yes I want the second form to be cascaded to the first form but No I do not want the size and location of the previous forms to be changed everytime we call this Cascade method. What should I do to fix this?

Upvotes: 0

Views: 601

Answers (1)

LarsTech
LarsTech

Reputation: 81620

That's what cascading is: it resizes them and lines them up in a step configuration.

If you just want to bring your other form to the top, you can try calling myChildForm.Select();

You can try to set the MinimumSize and MaximumSize properties equal to each form's Size before the cascade, and then restore them afterwards.

List<Size> minSizes = new List<Size>();
List<Size> maxSizes = new List<Size>();
for (int i = 0; i < this.MdiChildren.Count(); i++) {
  minSizes.Add(this.MdiChildren[i].MinimumSize);
  maxSizes.Add(this.MdiChildren[i].MaximumSize);
  this.MdiChildren[i].MinimumSize = this.MdiChildren[i].Size;
  this.MdiChildren[i].MaximumSize = this.MdiChildren[i].Size;
}

this.LayoutMdi(MdiLayout.Cascade);

for (int i = 0; i < this.MdiChildren.Count(); i++) {
  this.MdiChildren[i].MinimumSize = minSizes[i];
  this.MdiChildren[i].MaximumSize = maxSizes[i];
}

Upvotes: 1

Related Questions