Hello,

I was wondering if there was a way to cascade the windows any where on a form like in the middle or near the top left hand corner. I dont want the windows to cascade in the top left.

I can provide a pic if needed.

Recommended Answers

All 21 Replies

I think the way the cascade works is implemented in the MDIparent form and is automatic.
The only way I know to create a different effect is to implement it yourself by looping through the MdiChildren collection.

Could you give an example?

MdiChildren is an array of open child forms.
Use a for loop and modify the Size and Location of each form in turn.
Have a go and if you get stuck post your code for some help.

How would I do that?

Hi GAME, the policy here at daniweb is to help those who help themselves.
nick.crane has outlined the process you need to follow; write a method which iterates through the forms stored in the MDIParent's MDIChildren collection and sets the location and size for each form according to your desired layout.
Make an attempt at writing the method and if you get stuck, post what you have so far and we will advise on what to do next.

Im, sorry but I have never tried nor how to do what you are saying.

I guess ill mark it as solved even tho it isn't.

MSDN Form.MdiChildren Property
This link shows an example of using a for loop to do something (in this case add a button) to each form.
What you want to do is the same thing but change the something to be setting the forms position by changing the size and location properties of the form.
It should not be too difficult. Try and if you have problems then post again.:)

So when you click a button to open each form, run the open form and the void?

Then you'd do like if x = 1, put @ 10,10

then like x = 2 , put @ 10,10

So like,

private void CascadeChildren()
        {
            for (int x = 0; x < this.MdiChildren.Length; x++)
            {
                if (x == 1)
                {
                    Cascade.Location = new Point(10, 10);
                    Form Cascade = (Form)this.MdiChildren[x];
                    Cascade.Controls.Add(tempButton);
                }

            }
        }

I guess ill mark it as solved even tho it isn't.

Read the Daniweb Homework Policy to see why nick.crane has given you the tools to complete the task yourself rather than handing you the finished code to paste into your application.

This is a side project. For a community of a forum

Also; I am still learning on my own.

So like,

private void CascadeChildren()
        {
            for (int x = 0; x < this.MdiChildren.Length; x++)
            {
                if (x == 1)
                {
                    Cascade.Location = new Point(10, 10);
                    Form Cascade = (Form)this.MdiChildren[x];
                    Cascade.Controls.Add(tempButton);
                }

            }
        }

Thats a good start. You are iterating through the children in the collection (for future reference i'd suggest looking into the foreach loop too).
Your current code will set the location of the first form. You need it to move all of the forms.
Rather than doing if(x==1)...(if x==2)...etc, you need to think of a way to move each one with the same code.
Did you want all of them to be in the same place? Or would you like them to be staggered, so first form at (10, 10) second form at (20,20) etc?

OK. There has clearly been a misunderstanding of what you mean by the term Cascade.
If you want to have new forms positioned in a cascade patern then you do not need a for loop.
All you need to do is change the Location property to what you want (and possible the Size); using the MdiChildren.Length (or some other counter) to calculate the new position.

This is a side project. For a community of a forum

"Homework" doesnt necesarrily mean "school work" :) The idea of this forum is to help each other to learn. The best way to learn is by puzzling it out for yourself. Experimenting with the code and finding what works, what doesnt and most importantly, figuring out WHY.

We will happily recommend the right tools for the job and guide you through developing the code. But we arent going to hand you a perfect solution to paste into your code because we would be denying you the chance to find the solution for yourself.

Plus, we dont get paid enough ;)

I am having trouble setting the forms point. I get how to cascade the windows by point. If I were to know how to set the point. I would hopefully be on my way until I have another question.

You posted code that had

if (x == 1)
{
    Cascade.Location = new Point(10, 10);

Now think want would the Point(?,?) be if x=2 or x=3. Is there some relationship?
Also, in your code sample you set the forms position before you create the form. It needs to be the other way around.
Try again and post your code if it still does not work.

The form's location is determined by its Location propery. So you need to assign a new value to Form.Location.

If you want to "cascade" them you will need to set a different point for each form. I'd suggest setting its location to some multiple of x. ie:

Point newPoint = new Point(x*10, x*10);

That way each form will be slightly offset so that its title bar shows under the other forms (as is the definition of Cascaded Windows) :)

So I say this is correct?

I want to say THANK YOU!!!

private void CascadeChildren()
        {
            for (int x = 0; x < this.MdiChildren.Length; x++)
            {
                Form frm = (Form)this.MdiChildren[x];
                frm.Location = new Point(x * 10, x * 10);

            }
            
        }

Looks good to me.:) If resolved please mark solved.;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.