简体   繁体   中英

Why this code is changing my main Form Background color after I open it?

This code is changing my Main Form background color after I open it.

   private void button1_Click(object sender, EventArgs e)
    {
        this.IsMdiContainer = true;
        NewCustomer openform1 = new NewCustomer();
        openform1.MdiParent = this;
        openform1.Show();
    }

Also is creating a border in the top of my borderless form.

When you set this.IsMdiContainer = true WinForms is basically inserting an MdiClient control into the form for you, and that's what you're seeing rather than the actual form itself. By default it has a grey background and a sort of sunken-in appearance that was quite common in early Windows UI.

Changing the background is fairly trivial, as you can just set it on the MdiClient itself. You can find examples of that here:

Change Background of an MDI Form

Getting rid of the border is trickier because it's not directly exposed by the control itself, but you can find some approaches for that as well:

How to remove 3d border (sunken) from MDIClient component in MDI parent form?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM