Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7939243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:02:40+00:00 2026-06-03T23:02:40+00:00

I need to order windows in rectangle form. It’s mean that when I have

  • 0

I need to order windows in “rectangle” form. It’s mean that when I have six windows it orders it in rectangle 2×3, when I have 5 windows it orders it 2×3 but without last window, when I have 9 windows it orders in 3×3. But I’ve got some troubles with coordinates – child windows are out of bounds of mdiparent window.(img)

I used the same algorithm as I used in my mdi application on java

for(int i=0;i<a;i++)
    for(int j=0;j<b;j++)
         try{
             indfr.get(counter).setLocation(i*theDesktop.getWidth()/a,j*theDesktop.getHeight()/b);
             indfr.get(counter).setSize(theDesktop.getWidth()/a,theDesktop.getHeight()/b);
             counter++;
            }catch (IndexOutOfBoundsException exc){ break;}

where indfr - arralist of JInternalFrames,and theDesktop - JDesktopPane

Algorithm in c#

for (int i = 0; i < a; i++)
    for (int j = 0; j < b; j++)
            try
            {
                list[counter].SetDesktopLocation(i*list[counter].MdiParent.Width/a, j*list[counter].MdiParent.Height/b);
                list[counter].Size = new Size(list[counter].MdiParent.Width/a, list[counter].MdiParent.Height/b);
                counter++;
            }
            catch (IndexOutOfRangeException)
            {
                break;
            }

where list – Form[] list = this.MdiChildern;

What is wrong with coordinates?
(P.S it is not whole algorithm but it is the main loop where windows are ordering)

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:02:41+00:00Added an answer on June 3, 2026 at 11:02 pm

    The problem lines are those inside of your try block:

    list[counter].SetDesktopLocation(i*list[counter].MdiParent.Width/a, j*list[counter].MdiParent.Height/b);
    list[counter].Size = new Size(list[counter].MdiParent.Width/a, list[counter].MdiParent.Height/b);
    counter++;
    

    You’re checking Form.Width and Form.Height, which return the total size of the form on the screen, including all of the borders. You can only place child windows inside the client area of the parent form, so you need to query the ClientSize property instead. That is defined as the size of the form, minus the borders and title bar; in other words, the area of the form in which children can be placed.

    Re-write your try block to this, instead:

    list[counter].SetDesktopLocation(i*list[counter].MdiParent.ClientSize.Width/a, j*list[counter].MdiParent.ClientSize.Height/b);
    list[counter].Size = new Size(list[counter].MdiParent.ClientSize.Width/a, list[counter].MdiParent.ClientSize.Height/b);
    counter++;
    

    And then get rid of that silly empty catch block. If all you’re doing when an exception is thrown is breaking, then there’s no point in catching the exception. It will bubble up to the next exception handler, all the way to the global one if necessary. Only catch exceptions that you know specifically how to handle. You shouldn’t be getting an IndexOutOfRangeException, and if you do, that’s a bug in your code—you want to know about it so that you can fix it. That means not swallowing the exception.


    Clippy, the Office Assistant, now on Stack Overflow! But, if I may channel Clippy here, it looks like you’re trying to tile your MDI children.

    In that case, there’s an easier method than writing a bunch of for loops and manually setting the size and position of your children. Instead, just call the Form.LayoutMdi method on your parent MDI form, and specify one of the MdiLayout enumeration values. In this case, you probably want either MdiLayout.TileHorizontal or MdiLayout.TileVertical.

    WinForms will take care of arranging your child windows precisely how you want them automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C# command-line application that I need to run in windows and
I have my Windows Application that accepts args and I use this in order
I have an old Windows app, compiled in Visual C++ 6.0, that I need
I wrote a Python script that I need to have installed on Windows Server
I'm working on an order entry application targeted to windows mobile devices. I need
I need to order by 2 columns using the entity framework. How is that
I need to used dynamic order query in mysql and i have successfully achieved
I need to write a module that sends order data to an epayment service,
In order to get your application certified for Windows 8, Microsoft says that you
I need to create a Windows service that checks when a user logs in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.