MdiLayout.TileVertical doesn't work correctly

邮差的信 提交于 2019-12-11 07:36:31

问题


I had used MDI form in C# for displaying multi-windows. When I used MdiLayout.TileVertical to change the layout of my child windows, I couldn't get the correct result. Child windows had not be displayed vertically.

I wanted result:

1

2

3

4

What I had get :

3 1

4 2

My code source:

[STAThread]
    static void Main() 
    {            
        Application.Run(new Form1());
    }

    private void menuItemNew_Click(object sender, System.EventArgs e)
    {
        oFileDlg.CheckFileExists=true;
        oFileDlg.CheckPathExists=true;
        oFileDlg.Title="Open File - MDI Sample";
        oFileDlg.ValidateNames=true;
        oFileDlg.Filter = "jpg files (*.jpg)|*.jpg";

        if (oFileDlg.ShowDialog() == DialogResult.OK)
        {   
            try
            {
                //Create a new instance of the MDI child template form
                Form2 chForm = new Form2();
                //set parent form for the child window
                chForm.MdiParent=this;

                //increment the child form count
                count ++;
                //set the title of the child window.
                chForm.Text= "Child - " + count.ToString();

                chForm.fileloc=oFileDlg.FileName;

                chForm.FormBorderStyle = FormBorderStyle.Sizable;

                //display the child window
                chForm.Show();                  
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString(), "MDI Sample", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }

    private void menuItemClose_Click(object sender, System.EventArgs e)
    {
        //Gets the currently active MDI child window.
        //Form a = this.ActiveMdiChild;
        //Close the MDI child window
        //a.Close();

        this.Close();
    }       

    private void menuItemAI_Click(object sender, System.EventArgs e)
    {
        //Arrange MDI child icons within the client region of the MDI parent form.
        this.LayoutMdi(System.Windows.Forms.MdiLayout.ArrangeIcons);
    }

    private void menuItemCas_Click(object sender, System.EventArgs e)
    {
        //Cascade all child forms.
        this.LayoutMdi(System.Windows.Forms.MdiLayout.Cascade);
    }

    private void menuItemHoriz_Click(object sender, System.EventArgs e)
    {
        //Tile all child forms horizontally.            
        this.LayoutMdi(System.Windows.Forms.MdiLayout.TileHorizontal);

    }

    private void menuItemVert_Click(object sender, System.EventArgs e)
    {           
        //Tile all child forms vertically.
        //CheckWindows();
        this.LayoutMdi(System.Windows.Forms.MdiLayout.TileVertical);
    }

    private void menuItemMax_Click(object sender, System.EventArgs e)
    {
        //Gets forms that represent the MDI child forms 
        //that are parented to this form in an array
        Form [] charr= this.MdiChildren;

        //for each child form set the window state to Maximized
        foreach (Form chform in charr)
            chform.WindowState=FormWindowState.Maximized;
    }

    private void menuItemMin_Click(object sender, System.EventArgs e)
    {
        //Gets forms that represent the MDI child forms 
        //that are parented to this form in an array
        Form [] charr= this.MdiChildren;

        //for each child form set the window state to Minimized
        foreach (Form chform in charr)
            chform.WindowState=FormWindowState.Minimized;
    }

    private void menuItem1_Click(object sender, System.EventArgs e)
    {
        //Gets forms that represent the MDI child forms 
        //that are parented to this form in an array
        Form [] charr= this.MdiChildren;

        //for each child form set the window state to Minimized
        foreach (Form chform in charr)
            chform.Close();
    }

Is there any idea about this question?


回答1:


You can try to do docking on the child forms, and choose the desired output.

Eg : chForm.Dock = DockStyle.Left;



来源:https://stackoverflow.com/questions/50691902/mdilayout-tilevertical-doesnt-work-correctly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!