Controls in container form come over child form?

后端 未结 8 2236
天涯浪人
天涯浪人 2020-12-01 20:40

In a container form I have menu and buttons to open ther forms. \"enter

Here I am fac

8条回答
  •  悲&欢浪女
    2020-12-01 21:12

    I had this problem and solved it this way:

    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();
        }
    }
    

提交回复
热议问题