Shahrokh
Shahrokh

Reputation: 89

how to Show MDIChild Form on Top of the MDIParent's Controls

I have a MDI-Parent Form with many ChildForms, when I want to add a control on my Parent form, Child form appears under the control, For example I want to add a groupbox and a PictureBox on MDIParent Form, but when I call the Child Form it appears Under these controls.

frmChildForm1.TopMost=true doesn't works either.

I have attached a photo for more description.

What can I do?!

enter image description here

Upvotes: 1

Views: 2039

Answers (1)

Hans Passant
Hans Passant

Reputation: 942207

but I want to have an Image as Background

That's possible, you can set the BackgroundImage property of the MDI client control. The only obstacle is that you cannot directly get a reference to that control. You have to find it back by iterating the form's Controls collection. Like this:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        foreach (Control ctl in this.Controls) {
            if (ctl is MdiClient) {
                ctl.BackgroundImage = Properties.Resources.Lighthouse;
                break;
            }
        }
    }
}

Where Lighthouse was a sample image I added as a resource. Change it to use your own. Another common technique is to subscribe the Paint event for that control and draw whatever you want. A gradient is a common choice.

Upvotes: 2

Related Questions