Do controls in container form fall into child form?

In the container form, I have menus and buttons for opening forms.  enter image description here

Here I ran into a problem when I open any form, and these lines and lines fall into an open form. enter image description here

Please tell me how can I deal with this problem? I want to open a new form and save these container form elements in the background.

+3
source share
8 answers

I have the same problem too. I got an alternative solution as described below:

  • Insert a timer control
  • I added controls to the panel container
  • And did the following

    private void timer1_Tick(object sender, EventArgs e)
    {
        if ((int)MdiChildren.GetLength(0) > 0)
        {
            panel1.Visible = false;
        }
        else
        {
            panel1.Visible = true;
        }
    }
    
+5
source

MDI , . , .

.

expecially this:

. >

: ​​

+4

, , . MDI, MDI. - MDI-, -. , , BackColor Windows. , . , MDI MDI. , .

, . MDI, Panel Dock Left. . MDI , . . - , , , .

+4

@Hans Passant , , MDI. :

, .

+1

- . , . , TopLevel false, .

:

Form childForm = new Form(); //initialize a child form

childForm.TopLevel = false; //set it TopLevel to false

Controls.Add(childForm); //and add it to the parent Form
childForm.Show(); //finally display it

childForm.BringToFront(); //use this it there are Controls over your form.

+1

, . ? , ?

, Z-. , API Win32, SetWindowPos:

[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern bool SetWindowPos(
int hWnd, // window handle
int hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
uint uFlags); // window positioning flags


const uint SWP_NOSIZE = 0x1;
const uint SWP_NOMOVE = 0x2;
const uint SWP_SHOWWINDOW = 0x40;
const uint SWP_NOACTIVATE = 0x10;

And call it something like this:

SetWindowPos((int)form.Handle,   // that form
             (int)insertAfter.Handle,  // some other control
             0, 0, 0, 0,
             SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOACTIVATE);
0
source

Call BringToFront () for each child form after they are displayed. Also, bind it to each OnLoad child method:

childForm.OnLoad += (s, e) => (s as Form).BringToFront();
0
source

I had this problem and it was solved like this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

    Form2 F2;
    public Form1()
    {
        InitializeComponent();
        F2 = new Form2();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        Panel P1 = new Panel();
        P1.Location = new Point(0, 0);
        P1.Height = this.Height;
        P1.Width = this.Width;
        P1.BackColor = Color.Transparent;
        this.Controls.Add(P1);

        SetParent(F2.Handle, P1.Handle);
        F2.Owner = this;

        F2.Show();
    }
}
0
source

Source: https://habr.com/ru/post/1787996/


All Articles