C# MDI application: how to scale child windows when main window is re-sized?

Hi,
I have an MDI application that have several child forms.  Users can view several forms at one time, and users also are given the options to arrange the child forms anyway they want:  cascade or tile.  What I want to achieve is that if the
parent window is re-sized, all child forms should also be re-sized proportionally.   The code that I have only work if the child forms are tiled horizontally, AND that I only make the main window wider.  Otherwise, all forms are scaled (but not perfect),
however, the location is not scaled; therefore, they are overlapping each other.   I greatly appreciate any help from you.  
Size m_preSize;
private void MainForm_ResizeBegin(object sender, EventArgs e)
m_prevSize = this.ClientRectangle.Size;
private void MainForm_ResizeEnd(object sender, EventArgs e)
int iWidth = m_prevSize.Width;
int iHeight = m_prevSize.Height;
double dXFactor = (double)(this.ClientRectangle.Width) / (double)iWidth;
double dYFactor = (double)(this.ClientRectangle.Height) / (double)iHeight;
foreach (Form c in this.MdiChildren)
if (!c.Visible)
continue;
if (c.WindowState == System.Windows.Forms.FormWindowState.Maximized ||
c.WindowState == System.Windows.Forms.FormWindowState.Minimized)
// DO not ajust on resize if a child window is at its Maximized state
return;
c.Scale(new SizeF((float)dXFactor, (float)dYFactor));
Best Regards,
Emily

Hi Badidea,
Once again, I did not explain my idea clearly.  I am sorry about that.  I only wanted to scale the child-windows as the parent re-sized.  And yes, if the child-windows fill up the view-able area of the parent's window, I would like them to
also fill up the  view-able area of parent's window once again after re-size of parent window.  No scroll should be involved.
Regards,
Emily
Hello,
It depends on how you cascade or tile these forms.
In this case, I would recommend you use this way below.
1. Layout with splitContainers.
2. Set each child form's toplevel to false, then add them to the panels of splitContainers.
3. Resize these form to fit the panels.
4. repeat #3 inside the main form's resize event.
Here is a simple sample.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _150313AutoSizeMdiChiledForm
public partial class MainForm : Form
public MainForm()
InitializeComponent();
Form1 f1 = new Form1();
Form2 f2 = new Form2();
Form3 f3 = new Form3();
private void MainForm_Load(object sender, EventArgs e)
f1.TopLevel = false;
this.splitContainer2.Panel1.Controls.Add(f1);
f1.Size = this.splitContainer2.Panel1.ClientSize;
f1.Show();
f2.TopLevel = false;
this.splitContainer2.Panel2.Controls.Add(f2);
f2.Size = this.splitContainer2.Panel2.ClientSize;
f2.Show();
f3.TopLevel = false;
this.splitContainer1.Panel2.Controls.Add(f3);
f3.Size = this.splitContainer1.Panel2.ClientSize;
f3.Show();
private void MainForm_Resize(object sender, EventArgs e)
f1.Size = this.splitContainer2.Panel1.ClientSize;
f2.Size = this.splitContainer2.Panel2.ClientSize;
f3.Size = this.splitContainer1.Panel2.ClientSize;
Designer code.
namespace _150313AutoSizeMdiChiledForm
partial class MainForm
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
if (disposing && (components != null))
components.Dispose();
base.Dispose(disposing);
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.splitContainer2 = new System.Windows.Forms.SplitContainer();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit();
this.splitContainer2.SuspendLayout();
this.SuspendLayout();
// splitContainer1
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(0, 0);
this.splitContainer1.Name = "splitContainer1";
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
// splitContainer1.Panel1
this.splitContainer1.Panel1.Controls.Add(this.splitContainer2);
this.splitContainer1.Size = new System.Drawing.Size(607, 411);
this.splitContainer1.SplitterDistance = 198;
this.splitContainer1.TabIndex = 0;
// splitContainer2
this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer2.Location = new System.Drawing.Point(0, 0);
this.splitContainer2.Name = "splitContainer2";
this.splitContainer2.Size = new System.Drawing.Size(607, 198);
this.splitContainer2.SplitterDistance = 294;
this.splitContainer2.TabIndex = 0;
// MainForm
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(607, 411);
this.Controls.Add(this.splitContainer1);
this.Name = "MainForm";
this.Text = "MainForm";
this.Load += new System.EventHandler(this.MainForm_Load);
this.Resize += new System.EventHandler(this.MainForm_Resize);
this.splitContainer1.Panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit();
this.splitContainer2.ResumeLayout(false);
this.ResumeLayout(false);
#endregion
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.SplitContainer splitContainer2;
Result.
You could download it form http://1drv.ms/1Mwwibp.
It is quite similar with the one for tiling, you could edit it to fit your requirements.
Regards,
Carl
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • How to close child windows when parent window closed in jsp

    how to close child windows when parent window closed in jsp
    becoz it can't be able to recognise it's parent
    with the whole application
    plz send me some sample code of it

    Hi, I have no idea how to do this is JSP.
    However createing a modal window (with javascript) would mean that the user can not use the parent window untill he closes the child window. However not sure if this is what you are searching.
    Otherwise you can detect the onClose (I think) and close the window from there.
    However both the above are JavaScript and not JSP.
    rwgards,
    sim085

  • How to output particular text in main window only in first page

    Hi experts how to ouput particular text in main window only in first page after that actual transaction data will be continued.....any ideas....Answers will be rewarded.....

    Hi,
    Try this.
    /: IF &PAGE& = '1'
    /: ENDIF
    Thanks,
    Naren

  • In Smartform How to display footer & some secndry window after Main window?

    Hi,
    My requirement in Smartform is to display footer and and secondary window  after the Main window.
    also if item goes to 2nd & 3rd Page then also after main window footer and some secondary window should appear.
    Do i have to maintain footer and sec. window in Main Window itself
    Plz tell me in detail.
    Regards
    Vivek

    Hi Vivek,
    In smartform, specific legth is allocated to each window, that you create for a page.
    So, if you want to display secondary window on each page, create 1 secondary window with the required length and it will be displayed on each page.
    And you have written that you want to display the footer of main window also on all pages. It won't happen when you display your footer in main window. you will have to create a new window for your footer as well. Main window footer will always get displayed at the end of the main window.
    e.g. If your main window flows on second page, main window footer will be displayed on second page only.
    I hope this helps.
    Thanks,
    Archana

  • How to skip secondary window below main window  to next page.

    hi friends,
                          this is tax retail invoice in which main window contain a table where the items are listed
    as the items increses. the remaining items get listed on 2nd page thats ok..but the calculation part as total get
    calculated on both page in secondary window
    below main window
    tried with command with go to next page
    plse suggest.soon...urgent.
    thnx in advance.

    Put a condition on this secondary window for totals. Flag the checkbox 'Only after end of main window'.
    Cheers,
    Edwin.

  • Every time I try to open I get a window with a yellow background with window id="main-window" in red text how do I fix this? I have uninstalled and reinstalled several times

    I downloaded the new firefox 3.6.8 and since then it wont open Every time I try to open I get a window with a yellow background with <window id="main-window" in red text

    Try starting the profile manager ( [[Managing profiles]] ), making a new profile, [http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox migrating] the settings.

  • Lately, whenever I open a link in a new window, when that window opens it immediately minimizes down to the task bar. This is obviously annoying.

    Lately, whenever I "open a link in a new window", when that window opens it immediately minimizes down to the task bar. This is obviously annoying.

    Hi BigBinAz,
    Try to start firefox in [https://support.mozilla.org/en-US/kb/troubleshoot-extensions-themes-to-fix-problems safe mode], and in [http://kb.mozillazine.org/Safe_mode#Safe_Mode_options Safe Mode options] select ''Continue in Safe Mode'', don't make any changes in safe mode, and check it again.
    '''EDIT''' : "select ''Continue in Safe Mode'', don't make any changes in safe mode" '''there is not an option any more, the safe mode options don't exist any more''', so don't search for safe mode options.
    thank you

  • Dynpro application: how to perform some  code when user click window close

    Hello,
    I'm developing dynpro application. This application needs to perform some code when exiting.
    I can do that with MODULE xxxxx AT EXIT-COMMAND. But this code can't be performed when user of application click on button closing window (classic R/3 window, not pop-up).
    Does anybody know how to bind some code to clicking on button closing window?
    Best regards,
    Josef Motl

    As far as the prompt that you get when you close the last window is coming from the counter that SAP maintains regarding the number of open sessions(windows). When this counter reaches 1, I guess they have a check to issue a prompt. There was a discussion in this forum a long time back regarding how we can know that session id like SM04. There was no conclusion reached then. Theoritically, let us know you know this id for the session in which the user opened a particular page, then you can see if that session is deleted and then take the necessary action. There are some TH_* function modules that seem to be promising, but I was not able to conclusively achieve the control over a particular session.
    See if you can look at SM04 and get an idea. Please do let us know if you find the solution.
    Srinivas

  • How can I shut down when printer window is locked?

    How can I proceed to shut down when printer window is locked?

    Thank you, i will try this option. Only thing is i did read another person having this problem and he did shut down his computer and now his photo library in unaccessible!!! Ugh. I do have an external back up hard drive. I sure hope that my photos are on there to reload into iPhoto!!!!
    I did try to place my mouse over the iPhoto icon @ the dock and held down the control key with no results in shutting down the application.

  • How to print items in the MAIN window of the NEXT page (smartform)?

    Dear forumers,
    There are two pages (FIRST and NEXT) in my smartform with the same MAIN windows in each of the pages. Whatever that are changed in FIRST-MAIN window will also be seen in NEXT-MAIN window.
    I will need to control the printing of table TABLE3 contents (already contained in the MAIN window) such that if a variable V_MAT_PRINT is 'X', the TABLE3 contents will only be printed in NEXT page and not printed in FIRST page at all.
    How may I achieve this? Please help.
    Thank you.

    >
    Mohammed Ahasanullah Mulla wrote:
    > Hi Deborah,
    >
    > I had also faced a similar situation,in my case it was three pages..However i will try to tell you for 2 pages..After the second table .Add a program lines and force a page break only if V_MAT_PRINT is 'X'. After the program lines add a command and make the go to new page as second page.This will solve your problem.I have done the same and its working fine .If you have any questions do ask.
    >
    > Thanks,
    > Ahsan
    Hi Ahsan,
    Here's my case.
    If V_MAT_PRINT is 'X', print the following:-
    FIRST page, MAIN window
    - TABLE1
    - TABLE2
    - TABLE4
    - TABLE5
    NEXT page, MAIN window
    - TABLE3
    If V_MAT_PRINT is not 'X', print the following (no additional controls / changes are needed, everything remains unchanged):-
    MAIN window
    - TABLE1
    - TABLE2
    - TABLE3
    - TABLE4
    - TABLE5
    In this case, is a page break suitable? I doubt it as TABLE4 and TABLE5 will still need to be printed back on the FIRST page regardless of the V_MAT_PRINT value.
    Please advise further. Thanks.

  • How to Print text in two main windows

    For printing label have created two main windows on a page. calling function write_form In ABAP Program under do loop for two times. 
    but program prints only one window. why is it so? how can i print text on two windows.
    do 2 times.
      COUNT = COUNT + 1.
    loop at itab WHERE DEPTT LT 200.
        CALL FUNCTION 'WRITE_FORM'
          EXPORTING
            ELEMENT  = 'TEST'
            FUNCTION = 'SET'
            TYPE     = 'BODY'
          WINDOW   = 'MAIN'
          EXCEPTIONS
           ELEMENT   = 1
           FUNCTION  = 2
           TYPE      = 3
           UNOPENED  = 4
           UNSTARTED = 5
           WINDOW    = 6
           OTHERS    = 7.
      endloop.
    enddo.
    Please guide.

    Since the information is variable and coming out of the print program, I can assume you want to print many labels but two to a page. Also, any page numbering, etc will need to be updated. This is easily accomplished with SAPScript but a feature people rarely use I believe. Here are the simple steps:
    1) On the Windows Screen: Creat a main window for the size of the label, etc knowing that you will be putting multiple windows on a page. For example, if page size is 8.5 x 11, maybe your window size is 6 X 4 or something similar. You only need one main window defined.
    2) Now go to Page Windows Screen. Add a window MAIN and down at the bottom where it says Window Type put in MAIN. Next to this field is a little field about two characters long. In here put in '01'.
    3) Now Add another window MAIN and down at the bottom put in '02'.
    Hopefully this gives you the idea. I've done this with up to 30 small windows in order to print variable window for labels on label stock such as Avery 8167, etc. 
    Good Luck!
    Tim Stadler
    Menasha Corporation

  • How to skip secondary window if main window goes to next page

    hi gurus,
                  i m having a table in main window which lists items and its rate n quantity.
    the total price,discount and discount is calculated in secondary window.
    now if the list of item get more than window size it goes to next page but with calculation in both page in secondary window . i want to skip the calculation on 1st page.the calculation should only apear in scond page.
    thnx in advance.

    Hi..
    ******Case 1******************
    Suppose if you want display the Totals only in Last page :
    In the Secondary window:
    /: IF &NEXTPAGE(C)& = '0'
      <<DISPLAY YOUR TOTALS HERE>>
    /: ENDIF
    ***********case 2**************
    Suppose if you want display the Totals only in Last page :
    In the Secondary window:
    /: IF &PAGE(C)& = '2'
      <<DISPLAY YOUR TOTALS HERE>>
    /: ENDIF
    reward if Helpful.

  • How to summarize a field from main window at the bottom

    I've a requirement in sapscript which is driven by standard program RVADOR01 to print certain quotation details.There is a field called tax code(kbetr) which
    is required to be displayed for each line item .
    Now i've also to summarize these tax code at the bottom of the page in another window.Here is the scenario
    In MAIN window:
    kbetr
      1     for 1st line item
      1     for 2nd line item
      2     for 3rd line item
      1     for 4th line item
      3     for 5th line item
      2     for 6th line item
    It have to summerise above tax code in FOOTER window as:
    kbetr
      1
      2
      3

    Hi anutosh,
    1. First check out if summary variables
       are already available in the standard drive program or not.
    2. Further to this, the TEXT ELEMENTS
      for printing the summary should also be available.
    3. This all logic / sequence of printing
       is absolutely
       contained in the driver program.
    4. If its not there,
       then probably u will have to
       copy the driver program,
       and do some enhancements/modifictiions.
    5. I don't think, by simply manipulating
       the sapscript layout, we can achieve this directly.
    regards,
    amit m.

  • How to limit the size of main window height according to the line items?

    Hi,
    In my requirement,I created one page with main window in smartforms....Suppose say main window can accomodate 40 line items.
    I am getting 5 pages data.And in my last page ( ie 5'th page ) I will have only 20 line items.But for the remaing 20 line items,
    it showing empty area .I dont want this empty area .I want that window size to be restricted dynamically to that 20 line items.I created widow with borders and one vertical line between the columns.....I created two columns.
    Please I dont want any horizontal lines between the line items but I created one vertical line between the columns..
    This is in Smartforms
    Any right help would be appreciated.
    Thanks,
    Chinnu

    Hi Abhijit,
                    This problem is solved but I have the below another new problem.Can you pls help me in this regard.
                My requirement is to calculate the subtotal of a particular page and to print that subtotal
                at the end of each page.And this subtotal has to be carry forwarded as the first item of the next page(say page2).
                And again  at the end of this page(page2) I have to print the subtotal and needs to carry forward this subtotal again on to
                the first item of the page3..
               My problem is I am doing it in a table.I am calculating the subtotal and displaying the subtotal at the footer of the table..
               In the footer again I am redefining table work area values with the text 'Subtotal' and subtotal Amount so that thinking
               that it would print as first line item on the next new page....
              But the problem is I am getting subtotal as 2'nd line item on each new page instead of first line item of each page.........
              Can anyone resolve this issue.........
              I dont want this subtotal to be printed on the last page since I am getting Total of all these subtotals.....
              Below is my required structure
    Page 1.
                    Desc                               Amount
                    x                                      100
                    y                                      200
                   Subtotal                            300
    Page2.(Required page2)
                 Desc                               Amount                                
                    a                                      100
                    b                                      200
                   Subtotal                            600
    Page2.(But getting as below,which I dont require )
                    Desc                               Amount
                     a                                     100
                   Subtotal                            300
                     b                                      200
                   Subtotal                            600
    Page3.(Required page3)( I dont require Subtotal here on the last page)
                 Desc                               Amount                                
                    a                                      100
                    b                                      200
                   Total                                 900
    Any suggestions pls
    This is in Smartform
    Thanks,
    Chinnu

  • Did you change how Cmd-T opens tab when no windows displayed?

    One of my favorite Firefox commands was Cmd-T which, when no windows were displayed, brought up a new window with focus in the address bar so I could immediately type a new address or search. This eliminated CMd-N waiting for my home page to load, repositioning focus to address bar & erasing contents of address bar before typing a new address. Although not specifically documented, it was probably the Firefox cmd I most used. As of most recent update this has changed. It now opens a new tab in some hidden window but doesn't display it. This seems worthless. Please consider restoring this feature to the way it was. Thanks!

    I do Graphics/Production work for an archaeological firm. Before I started working here, they decided that of the different export options from our GIS department, EPS was the format that gave us the least problems and the highest quality. This was decided when we were using Illustrator 10. Now we're making the shift from CS2 and 3 to CS5 (getting our department on the same version), we are running into this problem with the EPS files and I am trying to find a solution to make all of our lives easier. One of the other options that we are kicking around is ditching the EPS file format all together and shifting to using a high quality PDF instead. Could this cause any loss of quality?

Maybe you are looking for